Load order of Java variables

Source: Internet
Author: User

Learning Programming Ideas

1  Packagecom.test.java.classs;2 3 /**4 * Created by Administrator on 2015/12/7.5 * Within the class, the order in which the variables are defined determines the order in which they are initialized. 6 * variables are initialized before any methods (including constructors) are called7  */8  Public classVariable {9      Public Static voidMain (string[] args) {TenHouse House =NewHouse (); One house.f (); A     } -  - } the  - classwindow{ -      PublicWindow (intN) { -System.out.println ("window-" +n); +     } - } +  A classhouse{ at     //1 -Window W1 =NewWindow (1); -  -      PublicHouse () { -         //4 -System.out.println ("House ()"); in         //5 -W4 =NewWindow (44); to         //6 +Window W2 =NewWindow (2); -     } the     //2 *Window W3 =NewWindow (3); $     voidf () {Panax NotoginsengSystem.out.println ("F ()"); -     } the     //3 +Window W4 =NewWindow (4); A  the}

Results:

Window-1
Window-3
Window-4
House ()
Window-44
Window-2
F ()

Load order of Java variables

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.