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
Given: What is the result?
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
Question is missing.
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 “;
};
}
Answer is E
fast
Exception in thread “main” java.lang.ClassCastException: SportsCar cannot be cast to Tank at Main.main(Main.java:7)