Detailed Print – Computer Sir Ki Class

Login


Lost your password?

Don't have an account ?
Register (It's FREE) ×
  


Shop
siteicon
Solved Problem#PYTHON#6472

Problem Statement - B02D-2016D

How do we implement abstract method in python? Give an example for the same.

Solution

Click to open popup

Solved Problem Understanding

Abstract method: An unimplemented method is called an abstract method. When an abstract method is declared in a base class, the derived class has to either define the method or raise “NotImplementedError”

class Shape(object):
    def findArea(self):
        pass
class Square(Shape):
    def __init__(self,side):
        self.side = side
    def findArea(self):
        return self.side * self.side