Why is it that all static methods and variables are accessible without any instance of class and non-static members need instances to get access.
-
3Can you Google this before asking on Stack Overflow? – Tim Biegeleisen Mar 30 '15 at 09:19
-
Possible duplicate of http://stackoverflow.com/questions/6569557/what-is-the-actual-memory-place-for-static-variables – tsnorri Mar 30 '15 at 09:20
-
3That is the very **definition** of `static`. `static` methods are on the `class` object, non-`static` methods are on an instance of that `class`. – Boris the Spider Mar 30 '15 at 09:21
2 Answers
Actually, there is a class object representing each class in the JVM. So, the line Why is it that all static methods and variables are accessible without any instance of class is incorrect.
The JVM creates class objects
(different from class instances
) representing classes.
Example : String.class
, Class.class
etc

- 35,966
- 12
- 68
- 104
When We create a class that means we are creating 'Bunch of Objects(instances) of Same type',for those objects,methods are remains same but data and memory location changes and it is unique for each object.But When We use 'Static' variable or Method ,It creates Only ONE COMMON COPY in whole program.So it is same for all instances/objects and changes done in static method/variable is visible to all objects. hence,we can use it directly or without instance of class.in same way,non static members are different with respect to every object,so we need instance of class for it.

- 11
- 3