Java Constructor Chaining
Consider the following Rectangle class definition:
public class Rectangle {
private double width;
private double height;
private String color;
public Rectangle() {
/* constructor body A */
}
public Rectangle(double w, double h) {
/* constructor body B */
}
public Rectangle(double w, double h, String c) {
/* constructor body C */
}
}
Which set of implementations for constructor bodies A, B, and C correctly uses constructor chaining to centralize all initialization logic in the three-parameter constructor?
A
A: this(1.0, 1.0, “white”); B: this(w, h, “white”); C: width = w; height = h; color = c;
B
A: width = 1.0; height = 1.0; color = “white”; B: width = w; height = h; color = “white”; C: width = w; height = h; color = c;
C
A: this(1.0, 1.0); B: width = w; height = h; color = “white”; C: width = w; height = h; color = c;
D
A: Rectangle(1.0, 1.0, “white”); B: Rectangle(w, h, “white”); C: width = w; height = h; color = c;
Question Leaderboard
| Rank | |||||
|---|---|---|---|---|---|
| #1 | kaisuki | 1 | 4 | 0m 00s | 70 |
| #2 | bommasam000 | 0 | 3 | 3m 29s | -239 |
| #3 | gtsak31 | 0 | 1 | 4m 05s | -255 |
| #4 | y.seong2027 | 1 | 2 | 13m 44s | -734 |
Items per page:
10
1 – 4 of 4
APFIVE