The second inheritance

Inheritance is achieved through the extends keyword

Definition: Inheritance is one of the three characteristics of object-oriented, and it is one of the means to achieve code reuse in Java. Only single inheritance is supported in Java, that is, each class can only have one direct parent class.

condition:

Inherit public and protected properties and methods, whether in a package or not.

Inherit the properties and methods modified by the default permission modifier, but the subclass and the superclass must be in the same package.

Cannot inherit private modified properties and methods.

The constructor of the parent class cannot be inherited.

 

Constructors in overriding and inheritance relationships:

Overridden requirements:

The overriding method and the overridden method have the same method name

2. The overriding method and the overridden method must have the same parameter list

3. The overriding method and return value type must be the same and subclass as the return value type of the overridden method.

4. Overriding methods cannot narrow the access rights of the overridden method.

 

super represents the default reference to the current immediate parent object.

super must appear in subclasses (methods and constructors of subclasses) and nowhere else

Can access the members of the parent class, such as the parent class. properties, methods, constructors.

Pay attention to the restrictions on access rights, such as the inability to access private members through super

 

abstract classes and abstract methods

1. Both abstract classes and abstract methods are modified by the adstract keyword

2. Abstract this instance. Abstract classes don't exist anymore. There are one or more abstract methods, or even all methods can be abstract methods

Abstract methods have only method declarations and no method implementations. A class with abstract methods must be declared abstract

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325348237&siteId=291194637