Question 1
Back to Exercise
The program below does not compile. Which statement correctly describes the problem?
class Phone {
String model;
Phone(String model) { this.model = model; }
}
public class Main {
public static void main(String[] args) {
Phone p = new Phone();
System.out.println(p.model);
}
}
- A model must be initialised
- B Phone declares a constructor, so no default constructor is generated; new Phone() has no matching constructor Correct
- C Phone must be public
- D model must be final
Correct Answer: Option B
Add Phone() { this("Unknown"); } or pass a model.
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!