Given:
What is the result?
A.
fast slow
B.
fast goes
C.
goes goes
D.
fast fast
E.
fast followed by an exception
F.
Compilation fails
Explanation:
Line:Vehicle v = new Sportscar();
causes compilation failure:
error: cannot find symbol
Vehicle v = new Sportscar();
symbol: class Sportscar
location: class VehicleTest
Incomplete question.
public class Main {
public static void main(String… ag) {
Vehicle v = new SportsCar();
System.out.println(v.goes());
Tank t = (Tank) v;
System.out.println(t);
}
}
class Vehicle {
public String goes() {
return “goes “;
};
}
class SportsCar extends Vehicle {
public String goes() {
return “fast “;
};
}
class Tank extends Vehicle {
public String goes() {
return “slow “;
};
}
fast
Exception in thread “main” java.lang.ClassCastException: SportsCar cannot be cast to Tank at Main.main(Main.java:7)
I tested.
E is the right answer.
E