Home > Java > Javagetting Started > How to inherit in java and what keywords to use?

How to inherit in java and what keywords to use?

(*-*)浩
Release: 2019-11-12 11:07:26
Original
4939 people have browsed it

How to inherit in java and what keywords to use?

#Inheritance is a cornerstone of Java object-oriented programming technology because it allows the creation of hierarchical classes.

Inheritance means that a subclass inherits the characteristics and behaviors of the parent class, so that the subclass object (instance) has the instance fields and methods of the parent class, or the subclass inherits methods from the parent class, so that the subclass has Same behavior as the parent class. (Recommended learning: java course)

Inheritance between classes can be achieved through the extends keyword

class 子类类名 extends 父类类名 {}
Copy after login

The inherited class is called The class inherited from the parent class, base class or super class

is called a subclass or derived class.

//父类
class Fu{}
//子类
class Zi extends Fu{}
Copy after login

Inheritance is the most significant feature of object-oriented. Inheritance is the derivation of a new class from an existing class. The new class can absorb the data attributes and behaviors of the existing class, and can expand new capabilities.

Java inheritance is a technology that uses the definition of an existing class as a basis to create a new class. The definition of a new class can add new data or new functions, or use the functions of the parent class, but You cannot selectively inherit from parent classes.

Characteristics of inheritance:

Through the extends keyword, after inheritance is implemented, a relationship is created between classes.

The essence of inheritance is to extract common code, extract multiple duplicate codes upwards, and simplify the code.

A class is an abstraction of a batch of objects, and inheritance is an abstraction of a batch of classes.

The parent class is also called the super class, or base class, and the subclass is also called the derived class.

Java is an object-oriented language, and everything is an object. In order to meet this design principle, all classes inherit directly or indirectly from the Object class.

The above is the detailed content of How to inherit in java and what keywords to use?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template