public class Box {
private int width;
public Box(int width) {
width = width;
}
}What is wrong with the constructor?
- A
Nothing is wrong
- B
private fields cannot be set in a constructor
- Ccheck_circle
The parameter shadows the field; assignment has no effect on the field
- D
Constructors cannot have parameters
Explanation
The parameter width shadows the instance field of the same name. The assignment width = width copies the parameter to itself; it should be this.width = width.