Oracle
1Z0-851 · Question #77
1Z0-851 Question #77: Real Exam Question with Answer & Explanation
Sign in or unlock 1Z0-851 to reveal the answer and full explanation for question #77. The question stem and answer options stay visible for context.
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.
Unlock 1Z0-851 to see the answer
You've previewed enough free 1Z0-851 questions. Unlock 1Z0-851 for full answers, explanations, the timed quiz mode, progress tracking, and the master PDF. Question stem and options stay visible so you can still see what's on the exam.
