Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Static variables?

 
Ganesan Ramakrishnan
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the use of static variables?
 
Ra Sank
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Static Variables are common to all the instances of a particular class where they declared and defined.
 
Darryl Burke
Bartender
Posts: 5126
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To put it more correctly, static variables are class members, not instance members.

edit: and exist independently of any instance of the class being constructed or not.
[ June 16, 2008: Message edited by: Darryl Burke ]
 
camilo lopes
Ranch Hand
Posts: 202
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
variable static you shared the value for all class and for one object scpecific. for example:
you are value dollar:


then this value �s shared for all class, not necessary create one instance for get the value this variable.
 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by camilo lopes:


Off-topic, but important: -

Never use "double" or "float" for money calculations. Use integer arithmetic (in cents, pence etc.) or BigDecimal. If you don't know why, read up on floating-point arithmetic and why it is unsuitable for currency calculations.
 
Ganesan Ramakrishnan
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for all ('=').
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic