Single Inheritance in Python

Dog(Animal) can speak() without defining it. That is the whole inheritance pitch.

BeginnerObject-Oriented ProgramsExample 4 of 25
single-inheritance.py
Run in browser
1# Program to demonstrate single inheritance
2
3class Animal:
4 def speak(self):
5 print("Animal makes a sound")
6
7class Dog(Animal):
8 def bark(self):
9 print("Dog barks")
10
11dog = Dog()
12dog.speak()
13dog.bark()

Output

Animal makes a sound
Dog barks

What's going on

Dog inherits from Animal, so instances of Dog can call both 'speak' and 'bark'.