Simple Inheritance

Imagine the following scenario.


1. You developed a class called Person with the following data to be used in
an address book application. We store name, address and mobile numbers in the Person class
2. The next project we are asked to manage Employee details so we plan an Employee class
The Employee class needs to store name, address, mobileno, post and salary.
The first 3 members are common to both classes. More importantly every Employee is a Person.
This is the exact situation in which inheritance is done.



Code


Imagine the following scenario.

1. You developed a class called Person with the following data to be used in
an address book application. We store name, address and mobile numbers in the Person class

2. The next project we are asked to manage Employee details so we plan an Employee class
The Employee class needs to store name, address, mobileno, post and salary.

The first 3 members are common to both classes. More importantly every Employee is a Person.

This is the exact situation in which inheritance is done.








Output





C:\Users\Lenovo\AppData\Local\Microsoft\WindowsApps\python3.10.exe C:/pythoncodecamp/OOPs/personemployeemanager.py
Name=Sachin, Address=Mumbai, Mobile=9987887654
Name=Sachin, Address=Mumbai, Mobile=9876543212, Post = Batsman, Salary=1000

Process finished with exit code 0



Git Repo


Contact us for software training, education or development










 

Post a Comment

0 Comments