Object Oriented Programming
Lab
CS123
Noushin Saba
Asfand Yar
Lab # 6
Inheritance
Inheritance
•One class acquires the properties and behavior of another class
•Represents a parent-child relationship between two classes
•Subclass
•A subclass, also known as a child class or derived class, is the class that inherits the properties
and behaviors of another class
•Superclass
•A superclass, also known as a parent class or base class, is a class whose properties and
behaviors are inherited by the subclass
•Implemented using the extends keyword
Account Class
•Superclass
•Attributes
•accountNumber, balance, and withdrawal limits
•Constructor
•No argument constructor
•Parameterized constructor
•Methods
•Set and get methods
•Depositing amount
•Withdrawing amount
•Calculating interest
•Displaying account information
CheckingAccount Class
•Subclass inherited from Account
•Attributes
•Overdraft Limit
•Constructor
•No argument constructor
•Parameterized constructor
•Methods
•Get and set methods
•Overrides withdraw method to handle overdrafts
•Overrides display information
Tasks
Task 1: Saving Account inherited from Account class
•Create a SavingAccount subclass with the following:
•Attributes
•Interest rate
•Constructor
•No argument constructor
•Parameterized constructor
•Methods
•Get and set methods
•Override calculate interest method
•Override display information
•Write main to check the functionality of SavingAccount
Tasks
•Task 2: Employee, Manager, Team Lead
Employee: This is the base class representing generic employees in the company. It
might contain attributes like name, employee ID, and methods for calculating salary
or displaying employee information.
Manager: The Manager class inherits from Employee and adds specific attributes
and behaviors relevant to managers, such as managing a team, approving leave
requests, or conducting performance reviews.
TeamLead: The TeamLead class further specializes in Managers. It inherits all the
attributes and behaviors of a Manager but may add additional features specific to
team leaders, like assigning tasks, mentoring team members, or coordinating team
meetings.
Tasks
•Employee class
•Attributes
•Name (first, last)
•Employee ID
•Employment status – Active
•Hire date
•Email address
•Phone number
•Department
•Position
•Salary
•Methods
•Get and Set Method
•Promote (change position)
•Terminate (change employment
status)
•Manager class
•Attributes
•Direct Reports (List of
Employees)
•Project (List)
•Methods
•Add direct reports
•Assign Projects
•Evaluate Performance
•TeamLead class
•Attributes
•Team name
•Team Tasks (List)
•Methods
•Hold team meeting
•Add and display team
tasks