Oracle
1Z0-851 · Question #77
Given: class Pizza { java.util.ArrayList toppings; public final void addTopping(String topping) { toppings.add(topping); } } public class PepperoniPizza extends Pizza { public void addTopping(String…
The correct answer is A. Compilation fails. See the full explanation below for the reasoning.
Question
Given: class Pizza { java.util.ArrayList toppings; public final void addTopping(String topping) { toppings.add(topping); } } public class PepperoniPizza extends Pizza { public void addTopping(String topping) { System.out.println("Cannot add Toppings"); } public static void main(String[] args) { Pizza pizza = new PepperoniPizza(); pizza.addTopping("Mushrooms"); } } What is the result?
Exhibit
Options
- ACompilation fails.
- BCannot add Toppings
- CThe code runs with no output.
- DA NullPointerException is thrown in Line 4.
How the community answered
(17 responses)- A82% (14)
- B6% (1)
- C12% (2)
Community Discussion
No community discussion yet for this question.
