What is inheritance in Java? Explain with an example.
December 26, 2024
Inheritance in Java is an object-oriented programming concept that allows one class (called the subclass or child class) to acquire the properties and behaviors (fields and methods) of another class (called the superclass or parent class). This promotes code reuse and establishes a hierarchical relationship between classes.
Syntax:
class Subclass extends Superclass {
// Additional fields and methods
}