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[])
	{
		StaticVariableDemo obj1 = new StaticVariableDemo();
		StaticVariableDemo obj2 = new StaticVariableDemo();
		obj1.increment();

		System.out.println("Obj1: count is:   " + obj1.count);//count is static -- called using an object
		System.out.println("count is:         " + count);//count is static -- do not need an object 
		System.out.println("Obj1: count2 is:  " + obj1.count2);//count2 is non-static -- must be reference by on object

		obj2.increment();
		System.out.println("obj2: count is:   " + obj2.count);//This shows each instance has a copy of the variable.
		System.out.println("obj1: count is:   " + obj1.count);//obj1 and 2 have access to the same copy of count.
		
		/*Can not access count2 with out 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*/
	}
}
