File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

STATIC & INSTANCE VARIABLE

 
dlc
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 39
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1272
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic