Sunday, June 23, 2024

Vehicle Using Inheritance in Python

 class Vehicle:

def move(self):
print("\tVehicle is moving.")

class Car(Vehicle):
def move(self):
print("\tCar is driving.")

if __name__ == "__main__":
vehicle = Vehicle()
car = Car()

print("\n\n\tVehicle Using Inheritance in Python\n")

vehicle.move() # Calls the base class method
car.move() # Calls the overridden method in the derived class

print("\n\tEnd of Program. Thank you for using this program.")

No comments:

Post a Comment