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?
public MiniPizza()public MiniPizza(String topping)public MiniPizza(String topping, int slices)
- I only
- II only
- III only
- I and II only
- II and III only
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.