Monday, September 11, 2006

What is the difference between an instance variable and a static variable? Give an example where you might use a static variable?

Class variables are called static variables. There is only one
occurrence of a class variable per JVM per class loader.
When a class is loaded the class variables (aka static
variables) are initialised.

Instance variables are non-static and there is one
occurrence of an instance variable in each class instance
(i.e. each object).

A static variable is used in the singleton pattern.A static variable is used with a final
modifier to define constants.

2 Comments:

At 11:35 PM, Blogger ashok said...

what is difference between jvm and a interpreter. is there any difference between these both.please reply at ashokmarvel@gmail.com

 
At 8:19 PM, Blogger Unknown said...

How to evaluate an expression on the basis of brackets?As in how can we evaluate a program whether the number of brackets that have been opened have been closed also.

 

Post a Comment

<< Home