The Java subclass inherits the parent class, and the order of execution when the subclass object is instantiated

Source: Internet
Author: User

subclasses inherit the parent class, and when the subclass object is instantiated, the order of execution is as follows:
Parent class-level static block
Self-static block
Parent Class Block
Parent class Constructor
Self block
Self-constructor because of inheritance, you should first load the parent class and then load the subclass, and the load class will naturally call the static block, then the constructor of the parent class, and the constructors of the subclass, but it is necessary to call the domain or block before the constructor is called, so that the object is created correctly.
················································
The order of assignment is as follows:
Static variable assignment for parent class
Static variable assignment of its own value
Parent class Member variable assignment
Parent Class block Assignment
Parent class constructor Assignment value
assigning values to self-member variables
Self-block assignment
Self constructor Assignment  for a class:      static code block/static member variable (in order of definition)      code block/member variable(in chronological order of definition)      constructor Function

The Java subclass inherits the parent class, and the order of execution when the subclass object is instantiated

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.