Question 5
Back to Exercise
The program below does not compile. Which statement correctly describes the problem?
class Order {
private final String id = "NEW";
Order(String id) {
this.id = id;
}
}
public class Main {
public static void main(String[] args) {
System.out.println(new Order("A1") != null);
}
}
- A id must be static
- B id already has an initialiser, so a final field cannot be assigned again in the constructor Correct
- C String cannot be final
- D this cannot be used with final
Correct Answer: Option B
Remove "= NEW" and assign it only in the constructor.
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!