classbase{ Public Static intA = 10; Public intb = 20; Static{System.out.println ("Static Init Base" +a); //System.out.println ("Null Init" + b); } PublicBase () {System.out.println ("Init Base" + This. b); }}//the first-class subclass and the base class contain the same contentclassSuperclassextendsbase{//static variables, static block execution order, by writing order Public Static intA1 =Getsuperstaticnumber (); Public intB1 =Getsuperinstancenumber (); PublicSuperclass () {System.out.println ("Init Superclass" + This. B1); } Static{System.out.println ("Static Init Superclass" +A1); } Public Static intGetsuperstaticnumber () {System.out.println ("Static member Init"); return100; } Public intGetsuperinstancenumber () {System.out.println ("Instance member Init"); return200; }}//Class Two subclasses are the driver classes that test the code Public classSubextendssuperclass{ Public Static intA2 =Getstaticnumber (); Public intB2 =Getinstancenumber (); PublicSub () {System.out.println ("Init Subclass" + This. B2); } Public Static intGetstaticnumber () {System.out.println ("Static member Init Sub"); return1000; } Public intGetinstancenumber () {System.out.println ("Instance member Init Sub"); return2000; } Static{System.out.println ("Static Init" +A2); } //program entry, main Public Static voidMain (String args[]) {NewSub (); }}
Static Init Base 10
Static member Init
Static Init SuperClass100
Static member Init Sub
Static Init 1000
Init Base 20
Instance member Init
Init SuperClass200
Instance member Init Sub
Init Subclass 2000
Static variables, static code blocks, members, constructs (from parent to child)
Loading order like Java basics