aspose file tools*
The moose likes Beginning Java and the fly likes STATIC & INSTANCE  VARIABLE Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "STATIC & INSTANCE  VARIABLE" Watch "STATIC & INSTANCE  VARIABLE" New topic
Author

STATIC & INSTANCE VARIABLE

dlc
Greenhorn

Joined: Feb 17, 2004
Posts: 3
Hi !!
Pleas tell me....
How to distinguish the practical urage between [STATIC] & [INSTANCE]VARIABLE??
And in what way can they be applied to?
thanks a lot
Gabriel Buheler
Ranch Hand

Joined: Apr 21, 2004
Posts: 39
An instance variable is used for each objetc you create of a certain class. Whereas an static variable is for an specific class.
Mike Gershman
Ranch Hand

Joined: Mar 13, 2004
Posts: 1272
If a variable can simultaneously have different values for different instances of a class (objects), it should be an instance variable. Examples are the account number, quantity, size, or name of an object.
If a variable is must always be the same at any given time for every instance of a class, it should be a static variable. Examples are final variables (constants), the object count, the next account number to be assigned, and dollar totals across all objects in a class.
Two special cases: Static methods can't access instance variables. Variables in interfaces must be static and final.


Mike Gershman
SCJP 1.4, SCWCD in process
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
dlc,
Welcome to JavaRanch!
We ain't got many rules 'round these parts, but we do got one. Please change your display name to comply with The JavaRanch Naming Policy.
Thanks Pardner! Hope to see you 'round the Ranch!


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: STATIC & INSTANCE VARIABLE