class Demo { int x=10; //non static variable static int y=20; // static variable void show() { System.out.println(x); // You get output System.out.println(y); // You get output } static void disp() { //System.out.println(x); // You get error //because static mentods can not accept non static variables System.out.println(y); // You get output } } public class Main { public static void main(String args[]) { Demo d=new Demo(); d.show(); // You get output d.disp(); // You get output System.out.println(d.x); // You get output System.out.println(d.y); // You get output //Note: By using object we have to call all static and non static variables and methods //Demo.show(); You Get error Demo.disp(); // You get output //System.out.println(Demo.x); // You get error System.out.println(Demo.y); // You get output //Note: By using class we have to call static methods and static variables only } }
10
20
20
10
20
20
20