Question: What is the output of the ElectricCar program? A. Driving vehicle B. Driving electric car C. Driving car D. The code does not compile. E.

What is the output of the ElectricCar program? 

package vehicles; class Automobile { private final String drive () { return

A. Driving vehicle

B. Driving electric car

C. Driving car

D. The code does not compile.

E. The code compiles but produces a ClassCastException at runtime.

F. None of the above.

package vehicles; class Automobile { private final String drive () { return "Driving vehicle"; } } class Car extends Automobile { protected String drive() { return "Driving car"; } } public class ElectricCar extends Car { public final String drive() { return "Driving electric car"; } public static void main(String[] wheels) { final Automobile car = new ElectricCar(); var v = (Car) car; System.out.print(v.drive ()); } }

Step by Step Solution

3.49 Rating (162 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

The provided image shows a segment of Java code with class hierarchy involving Automobile Car and El... View full answer

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 Oracle Questions!