Question: JAVA - Type the program's output import java.util.ArrayList; public class CallEmployee { public static void main ( String [ ] args ) { Employee person

JAVA
-
Type the program's output
import java.util.ArrayList;
public class CallEmployee {
public static void main(String[] args){
Employee person1;
Nurse person2;
Coach person3;
ArrayList personList = new ArrayList();
int i;
person1= new Employee();
person1.setName("Mia");
person2= new Nurse();
person2.setName("Aja");
person2.setHospital("City Hospital");
person3= new Coach();
person3.setName("Jose");
person3.setSport("basketball");
personList.add(person2);
personList.add(person1);
personList.add(person3);
for(i =0; i < personList.size(); ++i){
personList.get(i).printInfo();
}
}
}
public class Employee {
protected String name;
public void setName(String setName){
name = setName;
}
public void printInfo(){
System.out.println(name);
}
}
public class Nurse extends Employee {
private String hospital;
public void setHospital(String setHospital){
hospital = setHospital;
}
@Override
public void printInfo(){
System.out.println(name +" works at "+ hospital);
}
}
public class Coach extends Employee {
private String sport;
public void setSport(String setSport){
sport = setSport;
}
@Override
public void printInfo(){
System.out.println(name +" coaches "+ sport);
}
}

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!