Hi,
i am really confused with the concept of downcasting.can anyone explain me in context to the following question:
class Vehicle {}
class Car extends Vehicle {}
class VarArgSeven {
public static void washVehicle(Vehicle ... v) {
for(Vehicle vv : v) {
Car c = (Car)vv;
System.out.print(c);
}
}
public static void main(
String[] args) {
//insert the line here
}
}
Options :
a) washVehicle(new Car[] { new Car()});
b) washVehicle(new Vehicle[]{new Car(), new Vehicle()});
c) washVehicle(new Car(), new Car());
d) washVehicle(new Vehicle(), new Vehicle());
e) none of the above.
the answer to this is a and c but why not b and d too.
please explain.
thanks