When a class is derived from more than one base class, i.e., when a class has more than one immediate parent class, it is called multiple inheritance.
Example:
HybridEngine IS A ElectricEngine.
HybridEngine IS A CombustionEngine as well.
xxxxxxxxxx
class CombustionEngine():
def setTankCapacity(self, tankCapacity):
self.tankCapacity = tankCapacity
class ElectricEngine():
def setChargeCapacity(self, chargeCapacity):
self.chargeCapacity = chargeCapacity
# Child class inherited from CombustionEngine and ElectricEngine
class HybridEngine(CombustionEngine, ElectricEngine):
def printDetails(self):
print("Tank Capacity:", self.tankCapacity)
print("Charge Capacity:", self.chargeCapacity)
car = HybridEngine()
car.setChargeCapacity("250 W")
car.setTankCapacity("20 Litres")
car.printDetails()
xxxxxxxxxx
Multiple inheritance in Java programming is achieved or
implemented using interfaces. Java does not support multiple
inheritance using classes.
In simple term, a class can inherit only one class and multiple
interfaces in a java programs. In java terminology, we can say that
“A class can extend only one class but it can implement
multiple interfaces.”