Consider the following declarations. Employee employ1 = new Employee(); Manager employ2 = new Manager(); Employee employ3 = new Manager(); What will be printed if the code segment below is executed? employ1 = (Manager) employ2; employ1.work(); employ3.work();
This questions refers to the Employee, Manager, and Programmer classes incompletely defined below.
public class Employee
{
// Constructors and other methods here
public void work()
{
System.out.println(“Employee working.”);
}
// Instance fields here
}
______________________________________________________________________________
public class Manager extends Employee
{
// Constructors and other methods here
public void work()
{
System.out.println(“Manager working.”);
}
// Instance fields here
}
______________________________________________________________________________
public class Programmer extends Employee
{
// Constructors and other methods here
public void work()
{
System.out.println(“Programmer working.”);
}
// Instance fields here
}
Consider the following declarations.
Employee employ1 = new Employee();
Manager employ2 = new Manager();
Employee employ3 = new Manager();
What will be printed if the code segment below is executed?
employ1 = (Manager) employ2;
employ1.work();
employ3.work();
A. |
Manager working. Manager working. |
|
B. |
Employee working. Employee working. |
|
C. |
Nothing is printed. A ClassCastException occurs. |
|
D. |
Employee working. Manager working. |
|
E. |
Manager working. Employee working. |
Trending now
This is a popular solution!
Step by step
Solved in 3 steps