Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Java classes and the 'new' word

  1. #1
    Member Scotty's Avatar
    Join Date
    Oct 2010
    Posts
    60
    My Mood
    Scared
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Default Java classes and the 'new' word

    If you have a multidimensional array in a class and some methods. A state class.

    And other classes that built on that:

    State: including your array
    Play
    PlayerTypeA
    PlayerTypeB

    And you had a method (say move(int) - this is a game) in state accessible from PlayerTypeA/B. I assume you need State game =new State(); in both player classes and Play. The problem is the array in each class seems unique.

    How would I stop the deep copy effect from other classes. I need to affect the one in state using the methods in state. I dont know how to make my self clear. I am stuck on a uni assignment and cannot post code. It is the last bit and too late to ask for help. My methods in state cannot read the changes by my player classes, even though they can use the classes and print them. See my other post. Please help.

    the player class initializes state game

    game.move():

    but move seems to add the changes to a new array unique to that player class


  2. #2
    Member
    Join Date
    Mar 2011
    Location
    Earth!
    Posts
    77
    Thanks
    2
    Thanked 1 Time in 1 Post

    Default Re: Java classes and the 'new' word

    You dont need to do that in the classes constructors . Create the state object before you create instances of those classes and pass it along into their constructors.

Similar Threads

  1. im in a hurry!!Help with a programm..java game of guessing a word
    By mr_doctor in forum What's Wrong With My Code?
    Replies: 3
    Last Post: October 13th, 2010, 09:17 AM
  2. Word filter assignment help
    By normandygahn in forum What's Wrong With My Code?
    Replies: 3
    Last Post: September 15th, 2010, 08:42 AM
  3. Java: interfaces and abstract classes
    By pinansonoyon in forum Object Oriented Programming
    Replies: 1
    Last Post: May 6th, 2010, 11:17 AM
  4. How to invert a word String
    By Truffy in forum Java Programming Tutorials
    Replies: 16
    Last Post: October 3rd, 2009, 03:44 AM
  5. Problem in merging two java classes
    By madkris in forum Object Oriented Programming
    Replies: 11
    Last Post: March 16th, 2009, 10:02 AM