34 Ways to call Static data in Java

Code:

class Demo
{
static int a = 222;
}

public class Static
{
public static void main( String args[] )
{
//System.out.println(" By Directly= "+a); We cannot access it directly

System.out.println(" By Class Name= "+Demo.a);
Demo s = new Demo();
System.out.println(" By Reference= "+s.a);
System.out.println(" By Object= "+new Demo().a);
}


}


Output:  

Previous
Next Post »