QUESTION 38
Given:
1. public class Boxer1{
2. Integer i;
3. int x;
4. public Boxer1(int y) {
5. x = i+y;
6. System.out.println(x);
7. }
8. public static void main(String[] args) {
9. new Boxer1(new Integer(4));
10. }
11. }
What is the result?
A. The value 4 is printed at the command line.
B. Compilation fails because of an error in line 5.
C. Compilation fails because of an error in line 9.
D. A NullPointerException occurs at runtime.
E. A NumberFormatException occurs at runtime.
F. An IllegalStateException occurs at runtime.
Solution : D
오류 발생
Exception in thread "main" java.lang.NullPointerException
at Boxer1.<init>(Main.java:5)
at Boxer1.main(Main.java:9)
-->생성하지 않은 객체에서 해당 메소드를 사용하는 경우 발생
올바른 표현 :
1. 래퍼런스 변수 선언
2.객체생성 코드 추가
3.메소드 사용 가능
'자격증 > OCJP_ExamA' 카테고리의 다른 글
QUESTION 40 (0) | 2018.07.08 |
---|---|
QUESTION 39 (0) | 2018.07.08 |
QUESTION 37 (0) | 2018.07.08 |
QUESTION 36 (0) | 2018.07.08 |
QUESTION 35 (0) | 2018.07.06 |
#IT #먹방 #전자기기 #일상
#개발 #일상