Skip to content

Instantly share code, notes, and snippets.

@sudhanshuptl
Created May 28, 2018 04:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sudhanshuptl/1c14c5ab1c9dafe4a6954f4ee1485829 to your computer and use it in GitHub Desktop.
Save sudhanshuptl/1c14c5ab1c9dafe4a6954f4ee1485829 to your computer and use it in GitHub Desktop.
Abstract class in python
from abc import ABC, ABCMeta, abstractclassmethod
'''
Abstract classes are classes that contain one or more abstract methods. An abstract method is a method that is declared,
but contains no implementation. Abstract classes may not be instantiated, and require subclasses to provide
implementations for the abstract methods.
'''
# Class That can't be instantiated
class AbstractClassDemo(ABC):
@abstractclassmethod
def skills(self):
print('Hello')
#abs = AbstractClassDemo()
## It though error as Abstract class can't be instantiated
class Base(AbstractClassDemo):
def __init__(self):
self.name = 'Sudhanshu Patel'
def skills(self):
print('I am in Base Class')
def __del__(self):
class_name = self.__class__.__name__
print( class_name, 'Destroyed Successfully')
obj = Base()
obj.skills()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment