Python Practice › OOP Programs › Program 9
Single inheritance
Write a Python program that demonstrates single inheritance.
Output
eating and barking
Approach
- The child class lists one parent class in brackets.
Solution
class Animal: def eat(self): return "eating" class Dog(Animal): def bark(self): return "barking" d = Dog()print(d.eat(), "and", d.bark())Output
eating and barking
Line by line
Line 5
Dog(Animal) gives Dog everything Animal has.
Learn the concept
New to this topic? Read the lesson, then come back.