Superclass and subclass constructors use and inherit

Source: Internet
Author: User

Constructors are implicit static methods, and static methods cannot inherit, so constructors cannot inherit;

If another constructor is implemented in the parent class, the parameterless constructor disappears and can no longer be called;

By default, if the parent class constructor is not explicitly called, the default one is called;

When you write a subclass, you must call the parent class constructor (the default call to the parent class without a parameter constructor)

When the parent class has its own constructor (the default parameterless constructor in the parent class disappears), when you write a subclass, you must write your own constructor and call one of the constructors of the parent class in the child constructor to create the parent class , such as super (name), because you want to have subclasses, You have to have a parent class (super () This form of parent constructor can not write, only this one can not write )

If the parent class does not have a constructor written by itself or has a parameterless constructor, in which case the parent class has a parameterless constructor, such as: Parent () {}, where Super () is used in the subclass constructor, or it can be called without writing, because the system will be added by default.

Superclass and subclass constructors use and inherit

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: 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.