मराठी

How do we implement abstract method in Python. Support your answer with an example.

Advertisements
Advertisements

प्रश्न

How do we implement abstract method in Python. Support your answer with an example.

कोड लेखन
Advertisements

उत्तर

An abstract method may be declared in a parent class by raising NotImplementedError. A derived class implements it by overriding the method.

class Circle(object):
    def get_radius(self):
        raise NotImplementedError

class Circle1(Circle):
    def __init__(self, radius):
        self.radius = radius

    def get_radius(self):
        return self.radius

c = Circle1(10)
print(c.get_radius())

Output

10
shaalaa.com
  या प्रश्नात किंवा उत्तरात काही त्रुटी आहे का?
पाठ 4: Inheritance - EXERCISE [पृष्ठ ७८]

APPEARS IN

सीबीएसई Computer Science with Python [English] Class 12
पाठ 4 Inheritance
EXERCISE | Q 13. | पृष्ठ ७८
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×