Created
July 20, 2021 10:30
-
-
Save huytung228/7ecab3b9f683d9eb4f66238119f81d67 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from abc import ABC, abstractmethod | |
class Polygon(ABC): | |
@abstractmethod | |
def noofsides(self): | |
pass | |
class Triangle(Polygon): | |
# overriding abstract method | |
def noofsides(self): | |
print("I have 3 sides") | |
class Pentagon(Polygon): | |
# overriding abstract method | |
def noofsides(self): | |
print("I have 5 sides") | |
# Driver code | |
R = Triangle() | |
R.noofsides() | |
R = Pentagon() | |
R.noofsides() | |
# Error when instantiate abstract class | |
P = Polygon() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment