3 · Object-Oriented Core · lesson 15 of 41

Inheritance

Extending a class to reuse and specialize.

Java
class Animal {
    String name;
    void speak() { System.out.println("..."); }
}

class Dog extends Animal {
    @Override
    void speak() { System.out.println(name + ": woof"); }
}

Animal a = new Dog();   // upcast
a.speak();              // dynamic dispatch → "woof"
TIP
Click a node in the 3D class tree to highlight inherited members.
Loading 3D scene…
Key takeaways
  • ✓extends creates an 'is-a' relationship.
  • ✓@Override lets the compiler check you're really overriding.
  • ✓Method calls dispatch on the runtime type.