Leave a Reply 3

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


bob

bob

Question is missing.

Vasily

Vasily

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

gelete

gelete

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