Initialization order for multiple inheritance relationships

Source: Internet
Author: User
initialization order for multiple inheritance relationships



Parent Class Property---"Parent construction method---" Subclass attribute---"Subclass construction method

        

Note: When an object is created, the subclass constructor automatically invokes the constructor of the parent class, and if the subclass has a parameter construct, the parent class parameterless construct is not automatically invoked. The subclass must have an parameterless construct, or an error occurs when the object is created using an parameterless constructor. If the parent class property is not initialized, the parent class property is not invoked and the contents of the parent class construction method are directly gone. Then continue with the constructor method of the subclass. Similarly, if the attribute in the subclass is not initialized, the attribute is not taken, that is, the method body in the constructor method of the subclass is directly taken.


The constructor method is not overridden because it cannot be inherited.

method Overrides rule: The method name is the same; The argument list is the same; the return value type is the same or is its subclass; Access rights are not strict with the parent class


Super keyword to access members of the parent class

super can only appear in the method and construct method of subclasses

when Super calls the constructor method, it can only be the first sentence

Super cannot access the private property of the parent class


Abstract can also be used for methods---abstract methods

Abstract method has no method body

abstract methods must be in an abstract class

an abstract method must be implemented in a subclass unless the subclass is an abstract class


final modifier

the decorated class, which can no longer be inherited

modified method, cannot be overridden by a quilt class

the modified variable becomes a constant and can only be assigned when it is initialized.


abstract classes and abstract methods

abstract class cannot be instantiated

can have 0-multiple abstract methods

non-abstract classes must override all abstract methods of the parent class.

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.