1) Local variables
2) Instance variables
(non-static)
3) Static variables
1) Local variables:-
Variables
declared within a method or a block are known as local variables whose scope
and lifetime are available within corresponding function or block only.
2) Instance variables:-
Variables
declared within a class are known as instance variables.
They
are initialized at runtime when an object is created.
They're
initialized separate copies for every objects.
They
can be accessed through objects.
eg:-
objname.variablename;
3) Static variables(class variables)
Variables
declared within a class as static are known as static variables.
They
are initialized only one copy for class at compilation time.
They
can be shared by all the objects of that class.
They
can be accessed through class name.
eg:-
classname.variablename;
No comments:
Post a Comment