Given the following classes defined in separate files, what will be the effect of compiling and running this class
Test?
code
class Vehicle {
public void drive() {
System.out.println("Vehicle: drive");
}
}
class Car extends Vehicle {
public void drive() {
System.out.println("Car: drive");
}
}
public class Test {
public static void main (
String args []) {
Vehicle v;
Car c;
v = new Vehicle();
c = new Car();
v.drive();
c.drive();
v = c;
v.drive();
}
}
endCode
a)Generates a Compiler error on the statement v= c;
b)Generates runtime error on the statement v= c;
c)Prints out:
list
Vehicle: drive
Car: drive
Car: drive
endList
d)Prints out:
list
Vehicle: drive
Car: drive
Vehicle: drive
endList
answer
c
How 'c' will be correct.
Thanks,
Sri