Polymorphism and Method Overriding
Consider the following class definitions. What is printed when the main method in the Main class is executed?
class Vehicle {
public void start() {
System.out.print("Vehicle is starting");
}
}
class Car extends Vehicle {
@Override
public void start() {
System.out.print("Car is starting");
}
}
public class Main {
public static void main(String[] args) {
Vehicle v = new Car();
v.start();
}
}
A
Vehicle is starting
B
Vehicle is startingCar is starting
C
Compilation Error
D
Car is starting
Question Leaderboard
Not enough data yet to show leaderboard.
