Wednesday, April 18, 2007

What is the difference between class variable, member variable and automatic(local) variable?

The class variable is a static variable and it does not belong to any instance of class but shared across all the instances.
The member variable belongs to a particular instance of class and can be called from any method of the class.
The automatic or local variable is created on a method entry and valid within method scope and they have to be initialized explicitly.


uograde01a on May 9, 2010 at 10:45 PM said...

A member variable cannot be called from a static method.

Anonymous said...

If a member var is static then it should be..

Anonymous said...

If a variable is static in the class, it isn't named as 'member' variable, it is a 'class' variable.

Therefore member variables cannot be static. They are members of an instance.


Interview Questions On Java,Java EE Copyright © 2017. Reads: best tracker