Question: Trace the following code to determine what will be outputted when EmployeeProcessor is run: public class Employee { protected double salary; public double getSalary() {
Trace the following code to determine what will be outputted when EmployeeProcessor is run:
public class Employee {
protected double salary; public double getSalary() { return salary; } public void setSalary(double salary) { this.salary = salary; } }
class FullTimeEmployee extends Employee { private double bonus; public double getBonus() { return bonus; }
public void setBonus(double bonus) { this.bonus=bonus; }
@Override public double getSalary() { return salary + bonus; } }
class PartTimeEmployee extends Employee { @Override public double getSalary() { return salary / 2; }
public class EmployeeProcessor { public static void main(String[] args) { Employee justAnEmployee = new Employee(); justAnEmployee.setSalary(10000.0); FullTimeEmployee fulltimeemployee = new FullTimeEmployee(); fulltimeemployee.setSalary(10000.0); fulltimeemployee.setSalary(2000.0); PartTimeEmployee parttimeemployee = new PartTimeEmployee(); parttimeemployee.setSalary(10000.0); System.out.print("1. My salary is: " + justAnEmployee.getSalary()); System.out.print("2. My salary is: " + fulltimeemployee.getSalary()); System.out.print("3. My salary is: " + parttimeemployee.getSalary()); } } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
