• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Instance fields and objects

 
Tricia Lemay
Greenhorn
Posts: 15
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just checking to be sure I'm understanding correctly.

An instance field is a variable defined in a class. This is true.

This instance field is present in every object of the class.

The object is merely a reference to the value that is stored in the instance variable. The object is not a value in itself but just a state.

Is this correct? Or should I work on this somemore?
 
Svend Rost
Ranch Hand
Posts: 904
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Instance members are instance variables and instance methods of
an object and they can only be accessed or invoked through an
obj. reference.

The object is merely a reference to the value that is stored in the instance variable. The object is not a value in itself but just a state.


Object o = new Object();

In the line of code o is the pointer to the piece of memory representing
the object.

An object has a state which is the values of the current
instance members.

/Svend Rost
 
Tricia Lemay
Greenhorn
Posts: 15
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Seems like a whole "nother" language! My head hurts! So does every object have it's own value?
 
Svend Rost
Ranch Hand
Posts: 904
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


I guess it depends "value". How do you define it?
Generaly I find value a bad term to use in connection with objects,
as they arn't like strings or integers.

If I make two objects

Person p1 = new Person("John");
Person p2 = new Person("Jack");

then you'd might say that they have different value.

If we then make the following:
p1 = p2;

then we can say that they have the same "value", as the two
identifiers (that is, p1 and p2) point to the same object.

Hope it helped...

/Svend Rost
 
Tricia Lemay
Greenhorn
Posts: 15
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanx Svend,

Yes, it's helped. I don't like "value" either. Maybe I am just making the question harder than it is. (I think it is a badly worded question in the first place.

T/F

An instance field is a variable defined in a class for which every object of the class has its own value.

Well... I got a 50/50 chance on it don't I!

 
Edwin Keeton
Ranch Hand
Posts: 214
IntelliJ IDE Java Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
T/F

An instance field is a variable defined in a class for which every object of the class has its own value.


Ans: T

From the Sun Java tutorial:
Every time you create an instance of a class, the runtime system creates one copy of each class's instance variables for the instance.
 
Tricia Lemay
Greenhorn
Posts: 15
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanx Edwin!

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic