Multiple Inheritance

Demonstrate a class inheriting from more than one base class.

PythonIntermediate
Python
# 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

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