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?

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
The provided image shows a segment of Java code with class hierarchy involving Automobile Car and El... View full answer
Get step-by-step solutions from verified subject matter experts
