0% found this document useful (0 votes)
6 views1 page

Q6NEW1

The document presents a Python code example demonstrating single and multiple inheritance using classes. A Dog class inherits from Animal and overrides the speak method, while an ElectricCar class inherits from both Car and Engine, showcasing multiple inheritance. The output illustrates the functionality of each class and their methods.

Uploaded by

mauuudhoke07
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views1 page

Q6NEW1

The document presents a Python code example demonstrating single and multiple inheritance using classes. A Dog class inherits from Animal and overrides the speak method, while an ElectricCar class inherits from both Car and Engine, showcasing multiple inheritance. The output illustrates the functionality of each class and their methods.

Uploaded by

mauuudhoke07
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

class Animal:

def __init__(self, name):


self.name = name

def speak(self):
return "Animal speaks"

class Dog(Animal):
def speak(self):
return f"{self.name} barks"

class Engine:
def start(self):
return "Engine started"

class Car(Engine):
def drive(self):
return "Car is moving"

class ElectricCar(Car, Engine):


def charge(self):
return "Electric Car is charging"

print("1. Single inheritance ")


dog = Dog("Buddy")
print(dog.speak())

print(" ")
print("2. Multiple inheritance ")
tesla = ElectricCar()
print(tesla.start())
print(tesla.drive())
print(tesla.charge())

********OUTPUT*********

1. Single inheritance
Buddy barks

2. Multiple inheritance
Engine started
Car is moving
Electric Car is charging

You might also like