Static code block:
When a class is loaded (memory), (called first), the static code block is executed and executed once. Static blocks are often used to initialize class attributes. The execution class is called before it is loaded.
Non-static code block:
When a class object is created and loaded (memory), (first called), each created object, that is, each loaded object, and non-static code block, is executed once. It is called before the execution class object is loaded.
Before an object is loaded, the class must be loaded first.
Static and non-static methods: they are executed only when called. Static Methods belong to Classes. After loading a class, you can call static methods. Non-static methods belong to objects. After loading an object, you can call non-static methods.
The action of loading a class is not symbolic, but the action of loading an object is a new action and will be executed.
Simplified:
Static code block: the class is called once every time it is loaded into the memory and called first.
Non-static code block: class objects are called once every time they are loaded into the memory, and then the corresponding constructor is called first.
Static Method and non-static method: both are executed when the method is called, and the static method is called, provided that the class has been loaded into the memory; non-static method is called, the premise is that the class object has been loaded into the memory.
So,
When the class is loaded/When the class is loaded: [when the class is used, it will be loaded]
First, when the class object is generated, the class and all its parent classes will be loaded;
2. When accessing static members of the class;
Third: class. forname ("Class Name ");