Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Diff between instance variable and class variable

 
VishnuKumar Prasad
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi
plz give the difference between c++ and Java
and also difference between Instance variable and class variable
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is a link to an article listing the comparison of Java to C++ http://java.sun.com/docs/white/langenv/Simple.doc1.html
An instance variable is a variable that exists in each occurance or instance (object) of the class that is created. This is how you keep track of the attributes of each instance separately from the other instances.
When you say class variable I believe that you are referencing static variables. When the class is first loaded (before any instances are created) the static variable(s) is created. A static variable only exists once for all instances of the class. An example is the static variable pi in the math class. There is only 1 pi, and all the instances use it.
In addition there are local variables. These exist only inside methods and when the method invocation is over they cease to exist.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic