Home »
Python »
Python programs
Python | Implement Abstraction using Abstract class
Python Abstraction class implementation: Here, we are going to learn how to implement abstraction using abstract class?
Submitted by Pankaj Singh, on November 21, 2018
In this program, we are implementing the concept of Abstraction using Abstract Class. Here, VEHICLE is Abstract Class and CAR and BIKE are Child Classes. VEHICLE class have two unimplemented methods, which are implemented in child 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
Python class & object programs »