Parent class Subclass Construction method

Source: Internet
Author: User

Extract

A subclass cannot inherit an explicitly defined construction method of a parent class, and if you want to inherit the constructor of the parent class, you need to inherit it by overriding the constructor method and calling the constructor of the parent class in the method by super.

Three case notes:

1. No constructor is explicitly defined in the parent class, at which point there is actually a default parameterless constructor in the parent class. At this point, when you explicitly define any constructed method in a subclass, you can call the default method of the parent class without using super.


2 . The default parameterless construction method is explicitly defined in the parent class, so the subclass can define arbitrary construction methods without having to use super to call the constructor of the parent class .


3, the parent class display defines the construction method , but does not show the definition of the default parameterless construction method , then the subclass definition any constructor method needs to call the parent class by Super constructor method

Parent class Subclass Construction method

Related Article

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.