QUESTION 26자격증/OCJP_ExamD2018. 8. 4. 17:18
Table of Contents
반응형
QUESTION 26Given:class Pizza {java.util.ArrayList toppings;public final void addTopping(String topping) {toppings.add(topping);}public void removeTopping(String topping) {toppings.remove(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");pizza.removeTopping("Peperoni");}}What is the result?A. Compilation fails.B. Cannot add ToppingsC. The code runs with no output.D. A NullPointerException is thrown in Line 4.Solution : A
plus imformation
Main.java:13: addTopping(java.lang.String) in PepperoniPizza cannot override addTopping(java.lang.String) in Pizza;
overridden method is final
public void addTopping(String topping) {
^ Note: Main.java uses unchecked or unsafe operations. Note:
Recompile with -Xlint:unchecked for details.
1 error
반응형
'자격증 > OCJP_ExamD' 카테고리의 다른 글
QUESTION 28 (0) | 2018.08.05 |
---|---|
QUESTION 27 (0) | 2018.08.05 |
QUESTION 25 (0) | 2018.08.04 |
QUESTION 24 (0) | 2018.08.04 |
QUESTION 23 (0) | 2018.08.04 |
@IT grow. :: IT grow.
#IT #먹방 #전자기기 #일상
#개발 #일상