I have the following code segment, which is shown as follows along with its output
from abc import ABCMeta, abstractmethod
class AbstractClass(object, metaclass=ABCMeta):
@abstractmethod
def __init__(self, n):
self.n = n
print('the salary information')
class Employee(AbstractClass):
def __init__(self, salary, name):
self.salary = salary
self.name = name
super(AbstractClass,self).__init__()
emp1 = Employee(1000000, "Tom")
print(emp1.salary)
print(emp1.name)
I would like to let the subclass, e.g. Employee
, can also inherit the functionality implemented in the constructor of AbstractClass
. In specific, the print('the salary information')
I added:
super(AbstractClass,self).__init__() # which does not work