Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # PREVENT A USER FROM CREATING AN OBJECT OF THAT CLASS
- # + COMPELLS A USER TO OVERRIDE ABSYRACT METHODS IN A CHILD CLASS
- #ABSTRACT CLASS = A CLASS WHICH CONTAINS ONE OR MORE ABSTRACT METHODS
- #ABSTRACT METHOD = A METHOD THAT HAS A DECLARATION BUT DOES NOT HAVE AN IMPLEMENTATION
- from abc import ABC, abstractmethod
- class Vehicle(ABC):
- #-----------------------------------------
- @abstractmethod
- def go(self):
- pass
- def stop(self):
- pass
- #------------------------------------------
- class Car(Vehicle):
- def go(self):
- print("You drive the car")
- def stop(self):
- print("This car is stopped")
- #------------------------------------------
- class Motorcycle(Vehicle):
- def go(self):
- print("You ride the motorcycle")
- def stop(self):
- print("This motorcycle is stopped")
- #-------------------------------------------
- #vehicle = Vehicle()
- car = Car()
- motorcycle = Motorcycle()
- #vehicle.go()
- car.go()
- motorcycle.go()
- car.stop()
- motorcycle.stop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement