import java.io.*;


public class StaticVariableDemo
{
	
	/*Only one copy of this variable needed.  
     No object needed to access this variable the default value is 0*/
	static int count;
	
	/*Each instance of this class has a copy of this variable. 
     Instance needed for access of the variable.*/
	public int count2 = 0;
	
	
	
	public void increment()
	{
		count++;
		count2++;
	}
	
	public static void main(String args[])
	{
		//Instance variables
        StaticVariableDemo obj1 = new StaticVariableDemo();
		StaticVariableDemo obj2 = new StaticVariableDemo();
        
		obj1.increment();
        
        //count is static -- called using an object
		System.out.println("Obj1: count is:   " + obj1.count);
        
        //count is static -- do not need an object
		System.out.println("count is:         " + count);
        
        //count2 is non-static -- must be reference by on object
		System.out.println("Obj1: count2 is:  " + obj1.count2);

		obj2.increment();
        
        //This shows each instance has a copy of the variable.
		System.out.println("Obj2: count is:   " + obj2.count);
        
        //obj1 and 2 have access to the same copy of count.
		System.out.println("Obj1: count is:   " + obj1.count);
		
		/*Can not access count2 without an instance of StaticVariableDemo.
		If I tried to do the following I will get an error:  
         System.out.println(count2 is:  " + count2);  
         I would get an error because count2 is an instance variable*/
	}
}
