Python Programming - Polymorphism - Discussion
Discussion Forum : Polymorphism - General Questions (Q.No. 57)
57.
What is the output of the following Python code?
class Car:
def start(self):
return "Car starting"
class ElectricCar(Car):
def start(self):
return "Electric car starting"
def drive(car):
return car.start()
car = Car()
electric_car = ElectricCar()
print(drive(car))
print(drive(electric_car))
Answer: Option
Explanation:
The
drive()
function demonstrates polymorphism, accepting both Car and ElectricCar instances and producing different outputs based on their specific implementations of the start()
method.
Discussion:
Be the first person to comment on this question !
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers