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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started