Single Inheritance

Show how a child class can inherit attributes and methods from a single parent class.

PythonBeginner
Python
# Program to demonstrate single inheritance

class Animal:
    def speak(self):
        print("Animal makes a sound")


class Dog(Animal):
    def bark(self):
        print("Dog barks")


dog = Dog()
dog.speak()
dog.bark()

Output

Animal makes a sound
Dog barks

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