Java / Object, Class and Package
When a class is initialized in Java?
After class loading, initialization of class takes place by initializing all static members of class.
A Java class's static initialization usually happens immediately before the first time one of the following events occurs:
- an instance of the class is created,
- a static method of the class is invoked,
- a static field of the class is assigned,
- a non-constant static field is used, or
- for a top-level class, an assert statement lexically nested within the class is executed.
Reflection can also cause initialization of class. Some methods of java.lang.reflect package may cause class to be initialized.
More Related questions...