class varibale : a data member which is declared with static modifier. Instance variable : a data member in a class with out static modifier.
The main difference between the class variable and Instance variable is,
first time, when class is loaded in to memory, then only memory is allocated for all class variables.
That means, class variables not depends on the Objets of that classes. what ever number of objects are there, only one copy is created at the time of class loding.
The main advantage of this class variable is, suppose if we want to maintain a counter to count the no of object of type that class, in that case we use variable counter as the static variable.
Thanks 4 ur explanation . It will help me as well as other persons ?
But my Q is can we tell the interviewer there r three types of variables
1. Instance variable
2. class variable
3. local variable
for his Q What are the types of variables in java ?.
thanks to participate in this forem .