Inheritance

Inheritance allows one class to acquire properties of another. Use the extends keyword.

class Animal {
  void sound() {
    System.out.println("Animal makes a sound");
  }
}

class Dog extends Animal {
  void bark() {
    System.out.println("Dog barks");
  }
}

Dog inherits the sound() method from Animal.

← PrevNext →