Question: Form the subclass Manager from the class Employee. A Manager has a bonus. Supply a constructor to the Manager class that takes id, salary and

Form the subclass Manager from the class Employee. A Manager has a bonus.

Supply a constructor to the Manager class that takes id, salary and bonus of a Manager. The constructor initializes all the instance variables of a Manager object.

The toString method of Manager should yield a string such as

id = 222 salary = 15.0 bonus = 5.0 
public class Manager { private double bonus; } public class Employee { private int id; private double salary; public Employee (int theID, double theSalary) { id = theID; salary = theSalary; } public String toString() { return "id = " + id + " salary = " + salary; } } 

Here is a tester.

 public class EmployeeTester { public static void main(String [] args) { Employee e1 = new Employee(111, 10.0); Employee e2 = new Manager (222, 15.0, 5.0); System.out.println(e1.toString()); //prints id = 111 salary = 10.0 System.out.println(e2.toString()); //prints id = 222 salary = 15.0 bonus = 5.0 } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!