Java Initialization process

Source: Internet
Author: User

The Java initialization process and code sequencing are not related, and the order of execution is:

static member variables;

static domain;

member variables;

Construction method;

Note: There is a base class that executes the base class first and then executes the subclass.


Package com.init.order;


public class Fruit {

Public Fruit () {

System.out.println ("Fruit init function");

}

public int apple_2 = INTPRINTLN (2);

public static int apple_1 = INTPRINTLN (1);

static{

System.out.println ("static area");

}

static int intprintln (int i) {

System.out.println (i);

return 100;

}

}



Package com.init.order;


public class Apple extends fruit{

Public Apple () {

System.out.println ("Apple init function");

}

static int Apple = INTPRINTLN (20);

}



Package com.init.order;


public class Testmain {


/**

* @param args

*/

public static void Main (string[] args) {

TODO auto-generated Method Stub

New Apple ();

}

}

Execution Result:

1

Static area

20

2

Fruit init function

Apple init function

Java Initialization process

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.