Java Fundamentals: Rules for constructing methods in inheritance

Source: Internet
Author: User

One: Related rules

(1) The constructor of theparent class must be called during the construction of the child class
(2) Subclasses can use Super (argumentlist) in their own construction methods to invoke the construction method of the parent class;
Use this (argumentlist) to call other constructor methods of this class
If you use Super (ArgumentList) to invoke the constructor method of the parent class, you must write the first line of the subclass construction method.
(3) If the constructor method of the parent class is not explicitly called in the constructor of the subclass, the constructor method is called without a parameter by default. Equivalent to executing super () By default in the subclass constructor method
(4) If the constructor of the parent class is not displayed in the subclass construction method, and no argument is constructed in the base class, the compilation does not pass.

Two: Look at an example


Execution Result:
Superclass
Subclass N =400

Java Fundamentals: Rules for constructing methods in inheritance

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.