Java Fundamentals-Inheritance

Source: Internet
Author: User

1. Members of the parent class that cannot be inherited:

Private members, subclasses, and parent classes are not in the same package, using the members of the default access permission, the constructor method.

2. Access modifiers:

Access decoration into similar bun class other

Private√

Default (Friendly) √√

Protected√√√

Public√√√√

3. Sequence of initialization of multiple inheritance relationships

Parent Class Property-Parent class construction Method-Subclass attribute-Subclass Construction method

4. Method overloading differs from method overrides:

Positional method Name parameter list return value access modifier

Method overloading homogeneous same different unrelated unrelated

Method overrides subclass the same as same or its subclasses are not strict with the parent class

5.super keyword to access the parent class members, be aware that:

1) Super can only appear in the methods and construction methods of subclasses

2) Super Call constructor method, can only be the first sentence

3) Super cannot access the private members of the parent class

6. When the parent class does not need to be instantiated, the parent class can be declared as an abstract class.

Public abstract class Name {}

7. When a subclass must override a parent class method, the parent class method can be declared as an abstract method.

Requirements for abstract methods:

1) There is no method body for abstract method;

2) Abstract methods must be in the abstract class;

3) An abstract method must be implemented in a subclass, unless the subclass is also an abstract class.

public abstract void Method name () {};

Java Fundamentals-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.