-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathabstract_classes.py
More file actions
48 lines (31 loc) · 889 Bytes
/
abstract_classes.py
File metadata and controls
48 lines (31 loc) · 889 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# abstract classes uses
# prevent a user from creating an object of that class
# compels a user to override abstract 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
@abstractmethod
def stop(self):
pass
class Car(Vehicle):
def go(self):
print("You drive the car")
def stop(self):
print("The car has stopped")
class Motorcycle(Vehicle):
def go(self):
print("You ride the motorcycle")
def stop(self):
print("The Motorcycle has stopped")
# vehicle = Vehicle()
car = Car()
motorcycle = Motorcycle()
# vehicle.go()
car.go()
motorcycle.go()
car.stop()
motorcycle.stop()