Java – Inheritance
Inheritance: Enables one class to acquire the properties and behavior of another class using the extends keyword.
Example:
class Animal {
void eat() { System.out.println("This animal eats food."); }
}
class Dog extends Animal {
void bark() { System.out.println("Dog barks."); }
}
Dog myDog = new Dog();
myDog.eat();
myDog.bark();
No images available.