The IT Certification Resource Center

Featured Deal

Get CompTIA, Cisco, and Microsoft training courses free for a week.
Learn More ❯

Question 7:

Consider the class hierarchy shown below:

hierarchy

Consider the following code below:

 

1.  DrivingUtilities du;
2.  FourWheeler fw;
3.  Truck myTruck = new Truck();
4.  du = (DrivingUtilities)myTruck;
5.  fw = new Crane();
6.  fw = du;

Which of the statements below are true?

A. Line 4 will not compile because an interface cannot refer to an object.
B. The code will compile and run.
C. The code will not compile without an explicit cast at line 6, because going down the hierarchy without casting is not allowed.
D. The code at line 4 will compile even without the explicit cast.
E. The code will compile if we put an explicit cast at line 6 but will throw an exception at runtime.