Home » 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.


#Abstract Class
class Vehicle:
    def start(self,name=""):
        print(name,"is Started")
    def acclerate(self,name=""):
    def park(self,name=""):
    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")

    print("\nCar Object")
    c = Car()
if __name__=="__main__":main()


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 

Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.