North South University
Department of Electrical and Computer Engineering
CSE 215L: Programming Language II Lab
Lab – 9: Inheritance
Objective:
● To understand inheritance and its usage
● To learn to utilize inheritance to ensure reusability of existing code
Task:
1. Implement the following classes:
In main method, create a Faculty object and display name, age, salary and initial. Call
the toString() method of the Faculty object to display all of its information.
2. Implement the following classes:
Person Employee
- name: String - department: String
- age: int - designation: String
- address: String
/* constructor, accessor, mutator */
/* constructor, accessor, mutator */
PartTimeEmployee FullTimeEmployee
- hours: double - basic: double
- rate: double - allowance: double
/* constructor */ /* constructor */
/* accessor-mutator */ /* accessor-mutator */
/* toString */ /* toString */
+ salary(): double + salary(): double
The relationship is as follows:
Employee extends Person
PartTimeEmployee extends Employee
FullTimeEmployee extends Employee
Create an object for PartTimeEmployee and FullTimeEmployee and print their salary.
For FullTimeEmployee, basic is the base salary, i.e. 15000.
Allowance is usually provided as percentage, i.e. 25%.
So the total salary of a full time employee = 15000 + 25% of 15000 = 18750