Single Inheritance
Show how a child class can inherit attributes and methods from a single parent class.
BeginnerTopic: Object-Oriented Programs
Python Single Inheritance Program
This program helps you to learn the fundamental structure and syntax of Python programming.
# 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
Understanding Single Inheritance
Dog inherits from Animal, so instances of Dog can call both 'speak' and 'bark'.
Note: To write and run Python programs, you need to set up the local environment on your computer. Refer to the complete article Setting up Python Development Environment. If you do not want to set up the local environment on your computer, you can also use online IDE to write and run your Python programs.