Java practice-Interface and inheritance

Source: Internet
Author: User

How to construct the parent and child classes:

If there is a default parameterless constructor in the parent class, calls are made automatically in the constructor of the child class. If the parent class has its own constructor, and the parent does not have a default parameterless constructor, then in the constructor of the subclass, you must call a constructor of the parent class, and it must be called in the first statement of the constructed method, in the form super () If placed in another place can not reflect the function of the constructor, the program error.

"If there is no such constraint, then a method of the subclass that inherits from the parent class may use some of the variables in the parent class, and those variables are not initialized to produce some unpredictable consequences, so the object of the subclass must be constructed and hidden in the subclass object before the object of the child class is constructed. Use the keyword super to refer to the parent class object. ”

Java practice-Interface and 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.