Inheritance allows a class (child/derived) to use properties and methods of another class (parent/base), avoiding code duplication.
class Employee:
def info(self, name, salary):
self.name = name
self.salary = salary
print(f"The name is {self.name} and salary is {self.salary}")
class Programmer(Employee): # Inherits everything from Employee
def status(self):
print(f"{self.name} is currently inactive")
Programmer(Employee)
class Employee:
def info(self, name, salary): ...
class PersonalInfo:
def age(self, age): ...
class Programmer(Employee, PersonalInfo): ...
Programmer
inherits from both Employee
and PersonalInfo
class Employee:
a = 23
class Programmer(Employee):
b = 43
class Coder(Programmer):
c = 34