问题详情

1. class Pizza {  2. java.util.ArrayList toppings;  3. public final void addTopping(String topping) {  4. toppings.add(topping); 5. }  6. }  7. public class PepperoniPizza extends Pizza {  8. public void addTopping(String topping) {  9. System.out.println(”Cannot add Toppings”);  10. }  11. public static void main(String[] args) {  12. Pizza pizza = new PepperoniPizza();  13. pizza.addTopping(”Mushrooms”);  14. }  15. }  What is the result?() 


A、 Compilation fails.

B、 Cannot add Toppings

C、 The code runs with no output.

D、 A NullPointerException is thrown in Line 4.

时间:2021-12-28 23:24 关键词: SCJP程序员认证考试

答案解析

A
相关问题