Polymorphism and Method Overriding
What will be printed when the program 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
Compilation Error
B
Vehicle is starting
C
Vehicle is startingCar is starting
D
Car is starting
Question Leaderboard
Not enough data yet to show leaderboard.
APFIVE