Home > Java > javaTutorial > body text

Builders and inheritance

WBOY
Release: 2024-09-10 06:30:38
Original
1072 people have browsed it
  • In a class hierarchy, both superclasses and subclasses can have their own constructors.

  • The superclass constructor is responsible for constructing the part of the object that corresponds to the superclass.

  • The subclass constructor is responsible for constructing the part of the object that corresponds to the subclass.

  • In practice, object construction is done in two steps: first, the superclass is constructed and then the subclass.

  • If only the subclass defines a constructor, the superclass constructor is automatically called to construct the superclass part of the object, using the superclass's default constructor.

  • Example: Here is a version of the Triangle class that defines a constructor and makes style private, being set by the constructor.

Construtores e herança

Construtores e herança

The above is the detailed content of Builders and inheritance. For more information, please follow other related articles on the PHP Chinese website!

source:dev.to
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!