0
Inheritance1 / 4

CRASH COURSE

Inheritance

A subclass inherits attributes and methods from a parent: class Dog(Animal). It gets everything Animal has.

  • Define a method with the same name in the subclass to override it. super() calls the parent version when you still need it.
  • Use inheritance for real "is a" relationships. A Dog is an Animal; an Engine is not a Car.
class Animal:
    def speak(self):
        return "..."

class Dog(Animal):
    def speak(self):
        return "Woof"