Skip to content

Commit 0fce51c

Browse files
authored
added abstract class👩‍💻
1 parent eb24eeb commit 0fce51c

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

Beginner_Level/Abstract Class.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
2+
from abc import ABC, abstractclassmethod # abc - abstract base class & python don't provide any abstract class there is a built-in modules which is in this line
3+
4+
5+
class Shape(ABC):
6+
@abstractclassmethod # its decorator
7+
def area(self): pass # empty method
8+
9+
#@abstractclassmethod # abstractmethod is a mthd which must be implemented in subclass
10+
def perimeter(self):pass
11+
12+
class Square(Shape):
13+
def __init__(self, side):
14+
self.__side = side
15+
def area(self):
16+
return self.__side * self.__side
17+
def perimeter(self):
18+
return 4 * self.__side
19+
20+
21+
square = Square(5) # it can't be intantiated bcoz its abstract class
22+
print(square.area())
23+
print(square.perimeter())

0 commit comments

Comments
 (0)