What is the output of the following code?
public class A
public int x = 20;
public static int M()
A a = new A();
Compilation error since we can not create an object of class A in static method M.
Method M() will return 20 as output when it is called.
Compilation error since we can not access instance member x from static method M.
We can create an object of an instance class inside a staic method, also we can access instance members from static members using instance name.
Back To Top