read the code bellow:select the right choice.
class vehicle{
public void drive(){
System.out.println("vehicle:drive");
}
}
class car extends vehicle{
public void dirve(){
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();
}
}
given choice:
A: vehicle:dirve
car:drive
car:drive
B: vehicle:drive
car:drive
vehicle:drive
the given answer:A
In my option A is right.but saw a similar question(one of simulate mock
exam) ,in which after the "v=c v.drive" ,the compile print out
"vehicle:drive"
now I am not so sure now,which method shoud to use ,the type of c or the instance of c?
I beg your explaination sincerely..........