티스토리 뷰
Which of the following are true statements about the following code? (Choose all the apply)
import java.util.ArrayList;
import java.util.List;
public class ListNull {
public static void main(String[] args) {
4: List<Integer> ages=new ArrayList<>();
5: ages.add(Integer.parseInt("5"));
6: ages.add(Integer.valueOf("6"));
7: ages.add(7);
8: ages.add(null);
9: for(int age:ages) System.out.print(age);
}
}
A) Exactly three of the add statements uses autoboxing.
B) Exactly two of the add statements uses autoboxing.
C) The code compiles.
D) The code throws a runtime exception.
E) Exactly one of the add statements uses autoboxing.
5,7 라인은 int를 Integer로 바뀌는 오토박싱을 사용한다. 6라인은 그러지 않는데 이유는 valueOf() 는 Integer를 리턴하기 때문이다. for loop는 null을 int로 언박싱을 하려고 할때 NullPointerExceptiion runtime exception을 발생시킨다.
정답: B,C,D
참고
int java.lang.Integer.parseInt(String s) throws NumberFormatException
Integer java.lang.Integer.valueOf(String s) throws NumberFormatException
'ocjap를 위한 자바 기초 > oca' 카테고리의 다른 글
[ocajp] 람다식 문제 (0) | 2020.09.09 |
---|---|
ocajp default 인터페이스와 override, overload (0) | 2020.09.08 |
[ocjap] StringBuilder 문제 (0) | 2020.07.22 |
[ocjap] 생성자 Constructor (0) | 2020.05.29 |
- Total
- Today
- Yesterday
- xe addon
- XE
- 자바 smtp
- Python
- esql
- JDBC
- XE3
- proc
- 라이믹스 모듈
- C언어
- xe애드온
- ocjap
- php
- webix
- 자바
- C
- MySQL
- 플러터
- KG
- 오라클
- 문자열
- 이클립스
- 프로씨
- 파이썬
- 파싱
- ocajp
- 인포믹스
- EC
- 포인터
- 스크래핑
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |