Static Variable


/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package javaapplication4;

/**
 *
 @author krishna
 */
public class StaticVariable 
{   
    /* A static variable will have only one copy created inside JVM memory and the same copy is shared by all the instances
    of the given class */
    static int i=10;

    public StaticVariable() 
    {
        System.out.println("value of i: "+i);
        i++;
    }
    
    
    public static void main(String[] args
    {        
        StaticVariable sv1=new StaticVariable();    
        StaticVariable sv2=new StaticVariable()// Both objects the same i
    }
    
}

Output:
value of i: 10
value of i: 11