Loading order like Java basics

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.