What is the result?

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

Explanation:

Line:Vehicle v = new Sportscar();
causes compilation failure:
error: cannot find symbol
Vehicle v = new Sportscar();
symbol: class Sportscar
location: class VehicleTest



Leave a Reply 5

Your email address will not be published. Required fields are marked *


Tim

Tim

Incomplete question.

zdeDu

zdeDu

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 “;
};
}

gelete

gelete

fast
Exception in thread “main” java.lang.ClassCastException: SportsCar cannot be cast to Tank at Main.main(Main.java:7)

KashiHide

KashiHide

I tested.
E is the right answer.