Skip to content

Instantly share code, notes, and snippets.

@huytung228
Created July 20, 2021 10:30
Show Gist options
  • Save huytung228/7ecab3b9f683d9eb4f66238119f81d67 to your computer and use it in GitHub Desktop.
Save huytung228/7ecab3b9f683d9eb4f66238119f81d67 to your computer and use it in GitHub Desktop.
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