Explain in detail the usage of inheriting classes using externds keyword in Java

Understanding inheritance is the key to understanding object-oriented programming. In Java, an existing class is inherited through the keyword extends. The inherited class is called the parent class (super class, base class), and the new class is called the child class (derived class). Multiple inheritance is not allowed in Java. (1) Inherit

Executed in Eclipse:

. Each class in the java file will generate a corresponding class in the bin folder Class file. The execution result indicates that the derived class inherits all the methods of the parent class.

(2) Cover

Execution result:

Defining a method in a subclass with the same name as the parent class, return type and parameter type is called method override. The override of the method occurs between the child class and the parent class. In addition, super can be used to provide access to the parent class.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>