Problem of the Day
Wednesday, May 27, 2026
Problem:
Consider the following class declaration.
public class BouncingBall
{
private String color;
private double diameter;
public BouncingBall()
{ /* implementation not shown */ }
public BouncingBall(String color, double diameter)
{ /* implementation not shown */ }
// No other constructors are defined
}
Which of the following declarations will compile without error?
BouncingBall b1 = new BouncingBall();
BouncingBall b2 = new BouncingBall("green", 2.0);BouncingBall b3 = new BouncingBall("blue", 4);
- I only
- I and II only
- I and III only
- I, II, and III
The correct answer is d. The overloaded constructors in the BouncingBall class accept either no parameters (as in option I) or two parameters, a String and a double value (as in options II and III). The int parameter 4 in option III is auto-wrapped to a double value when the object is constructed.