A)
1) Instance variables (per instance variables)
2) Class variables (per class variables)
Per instance means for every object that no. of variables created.
Per class means only one variable is created.
Class scoped variables are 2 types
Static and non-static variables static variables are called class variables.
Ex:
Class test
{
int a; //instance variable
Static int b; //class variable
Void A ()
{
a=100;
b=200;
int c; //local variable
}
Void B()
{
a=90;
b=80;
c=50; //error
}
}
->In the above example “a” is non-static but has class scope. i.e., it is available all the methods of the class.
->non-static variable of a class is known as Instance variable.
->In the above example “b’ is static.
->static variable of a class is known as “class variable” in java.
->local variables cannot be static.
Comments
Post a Comment