java inheritance
时间: 2023-10-14 12:29:03 浏览: 92
Java inheritance is a mechanism by which one class can inherit properties and methods from another class. The class that is being inherited from is called the superclass or parent class, while the class that is inheriting is called the subclass or child class.
The subclass can access all public and protected properties and methods of its superclass, and it can also have its own properties and methods. This allows for code reuse and makes it easier to organize code into logical hierarchies.
To implement inheritance in Java, you use the "extends" keyword in the class declaration. For example, if you want to create a subclass called "Employee" that inherits from a superclass called "Person", you would declare it like this:
```
public class Employee extends Person {
// subclass code here
}
```
In this example, the Employee class would inherit all public and protected properties and methods from the Person class.
阅读全文