Object-oriented features-inheritance

1. The benefits of inheritance

  • Reduce code redundancy and improve code reusability
  • Facilitate function expansion
  • Provide prerequisites for the use of polymorphism

2. Inheritance format

class A extends B{}

A: subclass, derived class, subclass

B: parent class, base class, super class, superclass

Embodiment: Once the subclass A inherits the parent class B, the subclass A obtains all the properties and methods of the parent class B

​ Including private methods and properties, but cannot be called because of encapsulation

Three, description

  1. One class can be inherited by multiple classes

  2. Single inheritance of Java classes : a class can only have one parent class

  3. After the child class inherits the parent class, it gets all the attributes and methods declared by the direct parent class and the indirect parent class

  4. If a class does not explicitly declare the parent class, then such inherited from java.lang.Objectclass

    All classes inherit directly or indirectly in java.lang.Objectclass

    Thought that all these classes have the function of such declaration

Guess you like

Origin blog.csdn.net/weixin_45321793/article/details/109558800