Q:

Python | Implement Abstraction using Abstract class

belongs to collection: Python class & object programs

0

In this program, we are implementing the concept of Abstraction using Abstract Class. Here, VEHICLE is Abstract Class and CAR and BIKE are Child ClassesVEHICLE class have two unimplemented methods, which are implemented in child Classes.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Program:

#Abstract Class
class Vehicle:
    def start(self,name=""):
        print(name,"is Started")
    def acclerate(self,name=""):
        pass
    def park(self,name=""):
        pass
    def stop(self,name=""):
        print(name,"is stopped")

class Bike(Vehicle):
    def acclerate(self, name=""):
        print(name,"is accelrating @ 60kmph")
    def park(self, name=""):
        print(name,"is parked at two wheeler parking")

class Car(Vehicle):
    def acclerate(self, name=""):
        print(name,"is accelrating @ 90kmph")
    def park(self, name=""):
        print(name,"is parked at four wheeler parking")


def main():
    print("Bike Object")
    b=Bike()
    b.start("Bike")
    b.acclerate("Bike")
    b.park("Bike")
    b.stop("Bike")

    print("\nCar Object")
    c = Car()
    c.start("Car")
    c.acclerate("Car")
    c.park("Car")
    c.stop("Car")
if __name__=="__main__":main()

Output

Bike Object
Bike is Started
Bike is accelrating @ 60kmph 
Bike is parked at two wheeler parking
Bike is stopped
 
Car Object 
Car is Started 
Car is accelrating @ 90kmph
Car is parked at four wheeler parking
Car is stopped 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Python class & object programs

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Python | Implement Interface using class... >>
<< Python | Implementing setters and getters with the...