Question 2
Back to Exercise
The program below does not compile. Which statement correctly describes the problem?
class Circle {
double r;
Circle(double r) { this.r = r; }
Circle() {
System.out.println("default circle");
this(1.0);
}
}
public class Main {
public static void main(String[] args) {
System.out.println(new Circle().r);
}
}
- A r must be int
- B On Java 21 a this(...) call must be the first statement in a constructor Correct
- C Circle() cannot print
- D Only one constructor is allowed
Correct Answer: Option B
Move the print after this(1.0).
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!