aspose file tools*
The moose likes Beginning Java and the fly likes What is a differance here? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "What is a differance here?" Watch "What is a differance here?" New topic
Author

What is a differance here?

arun mahajan
Ranch Hand

Joined: Dec 07, 2001
Posts: 305
Hello,
I have written the following class in two fashion and could not understand what is the difference for object a in these case?
will "a" remain class variable for both cases?
aminur rashid
Ranch Hand

Joined: Sep 21, 2001
Posts: 79
Yes both will be the class variables.I don't think any difference apart from the instance of memory allocation.i.e the memory will be allocated at different times for both the cases.Can any one comment .
[ April 04, 2002: Message edited by: aminur rashid ]

Regards<br />Aminur
Corey McGlone
Ranch Hand

Joined: Dec 20, 2001
Posts: 3271
Be careful to use the correct terminology. When you refer to a "class variable", most people would probably infer that your referring to a static member. In the example you've given, the variable 'a' is an instance member, meaning that it belongs to an instance of class x, not the class x, itself.
Corey


SCJP Tipline, etc.
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
Originally posted by aminur rashid:
Yes both will be the class variables.I don't think any difference apart from the instance of memory allocation.i.e the memory will be allocated at different times for both the cases.

That's sort of correct. In both examples, the identifier was declared as an instance field member of the class (an instance of the variable will belong to a specific instance of the class), but that's not to say that it is a class variable. When referring to a class variable, it is a static variable that is being talked about - not an instance variable.
Good Luck.
Update: Round two goes to Corey.
[ April 04, 2002: Message edited by: Dirk Schreckmann ]

[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
 
wood burning stoves
 
subject: What is a differance here?