Java - Can we access instance variables within static methods ?


Ans. No and Yes.

No, because we cannot access them directly and Yes, because we can access them using object reference.

Explanation

Static methods belong to a class and not objects whereas non static members are tied to an instance. Accessing instance variables without the instance handler would mean an ambiguity regarding which instance the method is referring to and hence its prohibited.


See this picture and imagine the Class as a mold and flowers being 2 objects. 

Static methods belong to the mold and the member elements belong to the flower object. 

Lets say you want to access color ( instance variable ) within static method. Without object specifier or handler, its ambiguous for the compiler to tell which object you are referring to. Though you can always access using flower1.color or flower2.color where flower1 and flower2 are object references.