In the order of the parent class subclass, member variables, static variables, constructor creation in Java, this type of question is often asked in the interview.
So test it with the following code:
Public classTest { Public Static voidMain (String args[]) {Father F=NewSon (); }}classFather { PublicFather () {System.out.println ("Father Construct"); } Static intFatherstatic=printfatherstatic (); intFather=Printfather (); Static intprintfatherstatic () {System.out.println ("Print in Father static Mamber"); return0; } Static intPrintfather () {System.out.println ("Print in Father Class Mamber"); return0; }}classSonextendsFather { PublicSon () {System.out.println ("Son Construct."); } Static intSonstatic=printsonstatic (); intson=Printson (); Static intprintsonstatic () {System.out.println ("Print in son static Mamber"); return0; } Static intPrintson () {System.out.println ("Print in Son class Mamber"); return0; }}
The result of the operation is:
Print in Father Static Mamber
Print in son static Mamber
Print in Father class Mamber
Father Construct
Print in Son class Mamber
Son Construct
To summarize, draw the following conclusions:
The Order of creation is: the static variable of the parent class--The child class, the member of the parent class, the parent class, the constructor method of the child class, member variable-
In general, create a static method first, then create the member variables and constructor methods of the parent class, and then create the member variables and construction methods of the child class
Java Parent class child class member variable, static variable, constructor creation sequence