Created
May 28, 2018 04:17
-
-
Save sudhanshuptl/1c14c5ab1c9dafe4a6954f4ee1485829 to your computer and use it in GitHub Desktop.
Abstract class in python
This file contains hidden or 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, 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