Learn AP Comp Sci

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?


  1. BouncingBall b1 = new BouncingBall();

  2. BouncingBall b2 = new BouncingBall("green", 2.0);

  3. BouncingBall b3 = new BouncingBall("blue", 4);
  1. I only
  2. I and II only
  3. I and III only
  4. I, II, and III

Show solution:

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.