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 browser1# Program to demonstrate single inheritance23class Animal:4 def speak(self):5 print("Animal makes a sound")67class Dog(Animal):8 def bark(self):9 print("Dog barks")1011dog = 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'.