public abstract class Vehicle {
public abstract int wheels();
}
public class Bike extends Vehicle {
public int wheels() { return 2; }
}
// Usage:
Vehicle v;
v = new Bike();
System.out.print(v.wheels());What is printed?
- A
Runtime error
- B
Compile error: cannot declare Vehicle reference
- C
0
- Dcheck_circle
2
Explanation
Abstract classes can be used as REFERENCE types even though they cannot be instantiated. v refers to a Bike, and dispatch returns 2.