Important Notes about Static Variable:
** Class variables (Static Variables) are referenced by the class name itself, as in
test1.demo //Code is given below
** Static Variables are associated with the class, rather than with any object. So, every instance of the class shares a class variable /Static Variable, which is in one fixed location in memory. Any object can change the value of a class variable.
{
static int demo=0;
staticVariable()
{
demo++;
}
public static void main(String[] args)
{
staticVariable test1=new staticVariable();
System.out.println(“Value of demo in test1:”+test1.demo);
System.out.println(“***********************************” );
staticVariable test2=new staticVariable();
System.out.println(“Value of demo in test1:”+test1.demo);
System.out.println(“Value of demo in test2:”+test2.demo);
System.out.println();
}
}