forked from deepdalsania/tutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAbstractClassDemo.py
More file actions
39 lines (26 loc) · 851 Bytes
/
AbstractClassDemo.py
File metadata and controls
39 lines (26 loc) · 851 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
from abc import ABC, abstractmethod
# ABC stands for abstract base classes
''' An Abstract class have abstract and non abstract method both but abstract method must be
declare with @abstractmethod decorator and without body.'''
class Abstract(ABC):
@abstractmethod
def get_ab(self):
pass
@abstractmethod
def mul_ab(self):
pass
def display(self):
print("This is a non-abstract method of abstract class ")
class NonAbstract(Abstract):
def get_ab(self):
self.a = int(input("Enter value of a : "))
self.b = int(input("Enter value of b : "))
def mul_ab(self):
print("Multiplication is : ", self.a * self.b)
def show(self):
print("This is a non-abstract method of non-abstract class")
n1 = NonAbstract()
n1.display()
n1.get_ab()
n1.mul_ab()
n1.show()