Single inheritance
Write a Python program that demonstrates single inheritance.
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())eating and barking
Line by line
Dog(Animal) gives Dog everything Animal has.
Learn the concept
New to this topic? Read the lesson, then come back.