Python ProgrammingPython Programming

Create an Abstract class to override default constructor in Python

Making the __init__ an abstract method

from abc import ABCMeta, abstractmethod
 
 
class AbstractClass(object, metaclass=ABCMeta):
    @abstractmethod
    def __init__(self, n):
        self.n = n
 
 
class Employee(AbstractClass):
    def __init__(self, salary, name):
        self.salary = salary
        self.name = name
 
 
emp1 = Employee(10000, "John Doe")
print(emp1.salary)
print(emp1.name)
Sample output of above program.
10000
John Doe