Python Implement Abstraction using Abstract class

Python Abstraction class usage: Here, we will figure out how to execute deliberation utilizing conceptual class?

In this program, we are actualizing the idea of Abstraction utilizing Abstract Class. Here, VEHICLE is Abstract Class and CAR and BIKE are Child Classes.

VEHICLE class have two unimplemented strategies, which are actualized in youngster Classes.

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 

Leave a Comment

error: Alert: Content is protected!!