Abstract base class & @abstractmethod

from abc import ABCMeta, abstractmethod

# abstract base class
# In this class u cannot make objects

class shape(metaclass=ABCMeta):

def printarea(self):
return 0

class rectangle(shape):
type = "rectangle"
sides = 4

def __init__(self):
self.length = 6
self.breadth = 7

def printarea(self):
return self.length * self.breadth

rect1 = rectangle()

print(rect1.printarea())

Comments

Popular posts from this blog

Steps taken by a compiler to execute a C program

Tokens in C

Variables and Data Types in C