Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions