Python Programming - Polymorphism - Discussion
Discussion Forum : Polymorphism - General Questions (Q.No. 68)
68.
What is the output of the following Python code?
class Vehicle:
def start(self):
return "Generic vehicle starting"
class Car(Vehicle):
def start(self):
return "Car starting"
class Bike(Vehicle):
def start(self):
return "Bike starting"
def drive(vehicle):
return vehicle.start()
car = Car()
bike = Bike()
print(drive(car))
print(drive(bike))
Answer: Option
Explanation:
The
drive()
function demonstrates polymorphism, accepting both Car and Bike 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