How Java is constructed

Source: Internet
Author: User
When a class A inherits a Class B, Class B Inherits Class C, Class C inherits Class D, and then C, b; When the construct of a is executed, if there is a member variable, the member variable is executed, and finally the subclass inherits the parent class, and the subclass overrides a method of the parent class, and when the parent class constructs, The method called is not a method of the parent class, the method that is overridden by the subclass public class Structure {public static void main (string[] args) {new childd ();}} Class Father{father () {System.out.println ("construction 1111 of the parent class"); Write (); System.out.println ("Construction of the parent class 2222");} void Write () {System.out.println ("Write Method for parent class");}} Class CHILDD extends father{private int value = 1; Sleep s = new sleep (); Childd () {System.out.println ("Construction of the Subclass");} @Overridevoid write () {System.out.println ("Write Method value= for subclasses"     +value),//When the parent class constructs an override method that calls the subclass, but the subclass has not yet started constructing, so value is the default value of 0} }class Sleep{sleep () {System.out.println ("Construction Sleep Method");}}

  

How Java is constructed

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.