Page 151 - CTS - CSA TP - Volume 2
P. 151
COMPUTER SOFTWARE APPLICATION - CITS
// Create an instance of the Manager class
Manager manager = new Manager(“John Doe”, 50000, “IT”);
// Call the displayDetails method of the Manager class
manager.displayDetails();
}
}
Output:
Explanation:
• In this program, we have a superclass Employee and a subclass Manager.
• The Employee class has attributes name and salary, and a method displayDetails() to display employee
details.
• The Manager class extends the Employee class and adds its own attribute department.
• The Manager class overrides the displayDetails() method to display manager-specific details along with
employee details.
• In the Manager constructor, super(name, salary) is used to call the superclass constructor and initialize
inherited attributes.
• In the main method, we create an instance of the Manager class with a name, salary, and department, and
call the displayDetails() method.
TASK 3: Shape and its Subclasses
// Superclass
class Shape {
String color;
// Constructor
Shape(String color) {
this.color = color;
}
void displayColor() {
System.out.println(“Color: “ + color);
136
CITS : IT & ITES - Computer Software Application - Exercise 100