Java records -12-object-oriented inheritance

Source: Internet
Author: User

Java Object-Oriented inheritance

  1. Java is single-inheritance, meaning that a class can only inherit from another class (The inherited class is called the parent class [base class], the inherited class is called a subclass), and the inheritance in Java uses the extends keyword.

  2. When a subclass object is generated, Java defaults to calling the parent class's constructor without arguments. The construction method is then executed to generate the object of the parent class. Next, the constructor of the subclass is called, and the object of the child class is generated. [To create an object of a subclass, you first need to generate the object of the parent class, and there is no subclass object without the parent class object.] For example: Without a father, there is no child. ]

  3. Super Keyword: Super represents a reference to a parent class object.

  4. If a subclass uses super () to display a constructor method that calls a parent class, it will look for the constructor that corresponds to super () at execution time without looking for the parent class's constructor without parameters. As with this, super must also be the first execution statement of the constructor method, which cannot be preceded by other executable statements. This is strictly guaranteed to be a parent class object, and then the subclass object is generated.


Java records -12-object-oriented 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.