Python Practice › OOP Programs › Program 9

Single inheritance

EasyOOP Programs · 9 of 48

Write a Python program that demonstrates single inheritance.

Advertisement
Output
eating and barking

Approach

  1. The child class lists one parent class in brackets.

Solution

Python
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.

More oop programs

← All 48 OOP Programs

Leave a Comment