What methods are polymorphic in the Employee Hierarchy? How could we build a method like getRandShape() above but for use with Employees? If we built a getRandomEmployee() method that returns various Employee subclass objects; write a few lines of code that would demonstrate late binding /* * Employee.java - Abstract * This is the superclass of all workers in this company * All employees must have a name and social security number. */ //notice the abstract keyword? That prevents us from making objects of this type! public abstract class Employee { private String name; privateintsocial;
- What methods are polymorphic in the Employee Hierarchy?
- How could we build a method like getRandShape() above but for use with Employees?
- If we built a getRandomEmployee() method that returns various Employee subclass objects; write a few lines of code that would demonstrate late binding
/*
* Employee.java - Abstract
* This is the superclass of all workers in this company
* All employees must have a name and social security number.
*/
//notice the abstract keyword? That prevents us from making objects of this type!
public abstract class Employee {
private String name;
privateintsocial;
public Employee() {
}
public Employee(String newName, int newSocial) {
name = newName;
social = newSocial;
}
public String getName() {
returnname;
}
publicvoid setName(String name) {
this.name = name;
}
publicint getSocial() {
returnsocial;
}
publicvoid setSocial(int social) {
this.social = social;
}
publicabstractdouble calculateWeeklyPay();
}
The classes Employee, SalariedWorker, HourlyWorker are given below:
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 1 images