java object initialization order use

This article introduced, the use of the initialization of the Java object. For friends who need it, please refer to

Single category: (Static member variable & static initialization block) <(member variable & initialization block) <constructing function

Copy codecode is as follows:
PUBLIC Class Objects initialization order {
    public static void main(String[] args){
        Person p = new Person();
class Person{
Public Static String Staticfield = “Static Member Variable”;
public string field = “member variable”;
system.out.println (“Static initialization block”);
system.out.println (“initialized block”);
system.out.println (“Construct function”);


output results

Static member variables
Static initialization block
member variable
initialization block
Construction function
Inheritance class: (Parenting Static Member Variables & Parents Static initialization blocks) <(Substant Static Member Variables & Substant Static initialization blocks) <(parent variables & parent initialization block) <(parent constructor & Subclass variables) <(subclass initialization block & subclass constructor)

In parenting, it is determined according to the order of appearing.

Leave a Reply

Your email address will not be published. Required fields are marked *