Home >Java >javaTutorial >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{ }
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!