Java - Polymorphism
Given these classes:
What is the output when this program runs?
class Vehicle {
void start() { System.out.println("Vehicle starts"); }
}
class Car extends Vehicle {
void start() { System.out.println("Car starts"); }
}
class Bike extends Vehicle {
void start() { System.out.println("Bike starts"); }
}
public class Test {
public static void main(String[] args) {
Vehicle[] vehicles = {new Car(), new Bike(), new Vehicle()};
for (Vehicle v : vehicles) {
v.start();
}
}
}What is the output when this program runs?
