Learn AP Comp Sci

Problem of the Day

Monday, February 2, 2026


Problem:

Every instance of the class MiniPizza is a small pizza with crust, sauce, cheese, and a single, optional topping that can be specified during the construction of the pizza. MiniPizza objects without a topping have null for their topping, but have the sauce and cheese that all MiniPizzas have. Additionally, each pizza is cut into 8 slices during construction.

Which of these would be an appropriate header for a constructor of the MiniPizza class?

  1. public MiniPizza()
  2. public MiniPizza(String topping)
  3. public MiniPizza(String topping, int slices)
  1. I only
  2. II only
  3. III only
  4. I and II only
  5. II and III only

Show solution:

The correct answer is d. According to the problem statement, some pizzas will have no topping, and some pizzas will have one topping. Answers I and II, the headers for an overloaded constructor, will work just fine for these pizzas. Header III is incorrect because all pizzas have 8 slices—there is no need to send in that information via a parameter.