Sequence of Java program execution (code instance) that contains the inheritance relationship

Source: Internet
Author: User

Order of execution:

1, the parent class static block

2. Sub class static Block

3, the parent class block

4. Parent Class Builder

5, sub-class block

6. Sub-class Builder

Very basic and simple knowledge, but did not try and how to know that "thought" is not right. Code Validation:

Package com.java.test;

Class A {public
	a () {
		System.out.println ("parent Class A constructor");
	}
	{SYSTEM.OUT.PRINTLN ("parent Class A Block");}
	Static{system.out.println ("Parent Class A static block");}

public Class B extends a{public
	
	B () {
		System.out.println ("Subclass B Builder");
	{System.out.println ("Subclass B Block");}
	static {System.out.println ("Subclass B static Block");}
	public static void Main (string[] args)
	{
		new B ();
	}
}

Output results:





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.