☕ Java Beginner

What is inheritance in Java?

Answer

Inheritance is an OOP mechanism where a class (subclass/child) acquires the properties and behaviors of another class (superclass/parent) using the extends keyword. This promotes code reuse — common fields and methods are defined once in the parent and reused in all children. Example: class Dog extends Animal — Dog inherits all non-private fields and methods of Animal. Java supports single inheritance for classes (a class can extend only one class) but multiple inheritance through interfaces. The super keyword accesses parent class members. Every class in Java implicitly extends Object.