The things you are looking for, you will get it at the following
example.
1. Given the following classes defined in separate files:
If you run this program, you would get answer n. 3 :
Vehicle drive.
Car drive.
Car drive.
As same i gave you the before example.
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?
1.Generates a Compiler error on the statement v= c;
2. Generates runtime error on the statement v= c;
3. Prints out:
Vehicle: drive
Car: drive
Car: drive
4. Prints out:
Vehicle: drive
Car: drive
Vehicle: drive
Select the most appropriate answer.
Thanks,
Golam Sayeed