Initialization of classes in Java inheritance structure

Source: Internet
Author: User
Tags constructor inheritance

No way, that's the basis. The following program please first analysis, if the results (with the white font is the output) correct, that you are very familiar with the initialization of Java class, is a clearance, if not, then quickly review it.

Package nie.test.extend; Initialization of the

/** Child constructor:
* @author Dotjar
* 1. Parent static field
* 2. Parent static Block
* 3. Child static Field
* 4. Sub-static block * 5. Parent normal Field
* 6. Parent normal Block {}
* 7. Parent Constructor
* 8. Sub-normal field
* 9. Sub-normal Block {}
* 10. Sub-constructor
/
public class Test { public static void Main (string[] args) {
New Son ("s");
}
}

class Father {
static protected String s = "father_static_property_string";//1
Protecte D String B = "father_normal_property_string"; 5
Static {
S = "O";//2
System.out.print ("D");
System.out.print (s);
}
{
b= "R";//6
System.out.print ("a");
System.out.print (b);
}

Father () {
This ("@");
System.out.print ("1");//8
}

Father (String s) {
System.out.print (s);//7
}
}

Class Son extends Father {
public static string s = ' son_static_property_string ';//3
public String b = ' Son_nor Mal_property_string "; 9
StatIC {
s = "J";//4
System.out.print ("T");
System.out.print (s);
}
{
b = "3";//10
System.out.print ("6");
System.out.print (b);
}

Son () {
System.out.print (".");//11
}

Son (String s) {
This ();
System.out.print ("com");//12
}
}

Test your output, you can select the next row with the mouse to check.

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.