hai friends,
iam new member of this group, iam going to write the exam very soon,i need the result as soon as possible,pls
i got this question in 4test mock exam,
Given the following classes defined in separate files:
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();
}
}
What will be the effect of compiling and running this class Test?
Generates a Compiler error on the statement v= c
Generates runtime error on the statement v= c
Prints out:
Vehicle : drive
Car : drive
Car : drive
Prints out:
Vehicle : drive
Car : drive
Vehicle : drive
anyone can explain how it works,
thx
swarna