Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

B. Given that HourlyEmployee and SalariedEmployee are subclasses of FullTimeEmpl

ID: 3878896 • Letter: B

Question

B. Given that HourlyEmployee and SalariedEmployee are subclasses of FullTimeEmployee, suppose we have: FullTimeEmployee fullnew FullTimeEmployee(); HourlyEmployee hourly- new HourlyEmployee(0; SalariedEmployee salaried- new SalariedEmployee); Which one of the following assignments would be legal at (i) compile-time and/or (ii) run time? a. salaried = (SalariedEmployee) full; b, salaried= full; c. salaried= (FullTimeEmployee) full; d, hourly= (HourlyEmployee) full; write your answers below: C. d. Create Java code with the above statements to validate your answers. ( write a simple Class with main

Explanation / Answer

Answer:

a)

This statement will be legal at the complie time because of the cast. But it is not legal at runtime because full refers to an object of FullTimeEmployee and it cannot be assigned to salaried. Because they are of different type.

b)

This statement is not legal at compile time because the references are of different types.

c)

This statement is not legal at compile time because the references are of different types. The case here is meaningless because full already refers to FullTimeEmployee.

d)

This statement will be legal at the complie time because of the cast. But it is not legal at the run time because full refers to an object of FullTimeEmployee and it cannot be assigned to hourly. Because they are of different type.

Please provide your valuable feedback.