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))
Generic vehicle starting\nCar starting
Car starting\nBike starting
Bike starting\nCar starting
Car starting\nCar starting
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:

Your comments will be displayed after verification.