"If a worker wants to do his job well, he must first sharpen his tools." - Confucius, "The Analects of Confucius. Lu Linggong"
Front page > Programming > Builders and inheritance

Builders and inheritance

Published on 2024-10-31
Browse:717
  • 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

Release Statement This article is reproduced at: https://dev.to/devsjavagirls/construtores-e-heranca-2g8g?1 If there is any infringement, please contact [email protected] to delete it
Latest tutorial More>

Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.

Copyright© 2022 湘ICP备2022001581号-3