Question 9
Back to Exercise
The program below does not compile. Which statement correctly describes the problem?
class Vehicle {
Vehicle() { }
}
class Car extends Vehicle {
String model;
Car(String model) { this.model = model; }
Car() {
super();
this("Default");
}
}
public class Main {
public static void main(String[] args) {
System.out.println(new Car().model);
}
}
- A Vehicle must be abstract
- B A constructor can call either this(...) or super(...) as its first statement, not both Correct
- C model must be final
- D Car cannot extend Vehicle
Correct Answer: Option B
Car(String) already calls super() implicitly; Car() only needs this("Default").
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!