Characteristics of inheritance

Source: Internet
Author: User

example, the parent class is car

Subclass is Trush_car

    1. You can declare a parent class, create a subclass
      • Where the parent class can appear, the subclass can appear
      • Car Acar = new Trash_car ();
    2. Declaring what type, you can only call properties and methods of this type
      • As Acar cannot call the Fill_trush () method because there is no such method in the car parent class
    3. What type is created and what type of method is run
      • Push_back () is the parent class definition and the subclass inherits the method;

        Acar.push_back (); Calls a method of a subclass other than the parent class.

4. What type is created and what type can be cast

    • b= (Trash_car) Acar; Because Acar itself is a trash object created (although the declaration is not the same)

Characteristics of 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: 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.