Multiple inheritance is like a child inheriting traits from both parents. Just as a child can get their mother's eyes and father's height, a class in programming can inherit properties and methods from multiple parent classes, combining their features.
class Car:
def __init__(self,brand,model):
self.brand=brand
self.model=model
def full_function(self):
return f"{self.brand} {self.model}"
def fuel_type(self):
return "Petrol or Desiel"
class battery:
def battery_info(self):
return "This battery is mine"
class engine:
def engine_info(self):
return "This engine is mine"
class ElectricCarTwo(battery,engine,Car):
pass
my_new_tesla=ElectricCarTwo("Tesla","ModelX")
print(my_new_tesla.engine_info)
print(my_new_tesla.battery_info)
Output: This engine is mine This battery is mine
As you can see, ElectricCarTwo inherits class engine, battery and Car.
Top comments (0)