Multiple Inheritance

Demonstrate a class inheriting from more than one base class.

IntermediateTopic: Object-Oriented Programs
Back

Python Multiple Inheritance Program

This program helps you to learn the fundamental structure and syntax of Python programming.

Try This Code
# Program to demonstrate multiple inheritance

class Flyer:
    def fly(self):
        print("Can fly")


class Swimmer:
    def swim(self):
        print("Can swim")


class Duck(Flyer, Swimmer):
    pass


d = Duck()
d.fly()
d.swim()
Output
Can fly
Can swim

Understanding Multiple Inheritance

Duck inherits behaviors from both Flyer and Swimmer via multiple inheritance.

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.

Table of Contents