QUESTION 21자격증/OCJP_ExamD2018. 8. 4. 16:26
Table of Contents
반응형
QUESTION 21Given:class Animal {public String noise() {return "peep";}}class Dog extends Animal {public String noise() {return "bark";}}class Cat extends Animal {public String noise() {return "meow";}} ...30. Animal animal = new Dog();31. Cat cat = (Cat)animal;32. System.out.println(cat.noise());What is the result?A. peepB. barkC. meowD. Compilation fails.E. An exception is thrown at runtime.Solution : E
plus imformation
Exception in thread "main" java.lang.ClassCastException: Dog cannot be cast to Cat
at ClassTest.main(Main.java:31)
반응형
'자격증 > OCJP_ExamD' 카테고리의 다른 글
QUESTION 23 (0) | 2018.08.04 |
---|---|
QUESTION 22 (0) | 2018.08.04 |
QUESTION 20 (0) | 2018.08.03 |
QUESTION 19 (0) | 2018.08.03 |
QUESTION 18 (0) | 2018.08.03 |
@IT grow. :: IT grow.
#IT #먹방 #전자기기 #일상
#개발 #일상