Home > Java > javaTutorial > body text

What is a subclass in java?

青灯夜游
Release: 2019-11-16 14:36:31
Original
4911 people have browsed it

What is a subclass in java?

The definition of subclass in java is that in the class with inheritance relationship, the class in front of extends is a subclass. [Recommended learning: java course]

Inheritance is the abstraction of multiple types of things with common characteristics into one class. This class is the parent class of many types of things. The significance of the parent class is that it can extract the common features of multiple types of things.

The subclass inherits the parent class, which means that the subclass can reference something in the parent class. The keyword for inheritance is extends.

If there are methods with the same name, return type and parameter list in the subclass that are accessible in the parent class (can be inherited to the subclass), the methods inherited from the parent class will be overwritten.

A class that directly inherits Object can be called a subclass of Object, a class that indirectly inherits Object can be called an indirect subclass of object, and object is its indirect parent class or superclass.

Example:

public class Parent{
}
public class Child extends Parent{
}
Copy after login

There is an inheritance relationship between Parent and Child, then Parent is the parent class of Child and Child is the subclass of Parent. Since Parent and Child inherit the Object class by default, all Parent and Child are subclasses of Object.

The above is the detailed content of What is a subclass in java?. 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