Inheritance is one of the important concepts of Object-Oriented Programming (OOP) in Java.
It allows one class to acquire the properties and methods of another class. This helps us reuse code and avoid unnecessary duplication.
What is Inheritance?
Inheritance allows a child class to inherit variables and methods from a parent class.
Java uses the extends keyword to implement inheritance.
Simple Example
class Animal {
void eat () { System . out . println ( "Animal is eating" ); } }
class Dog extends Animal {
void bark () { System . out . println ( "Dog is barking" ); } }
public class Main {
public static void main ( String [] args ) {
Dog dog = new Dog ();
dog . eat (); dog .β¦