티스토리 뷰
Given the code fragment:
public class Switch13 {
public static void main(String[] args) {
boolean opt=true;
switch(opt) {
case true:
System.out.print("True");
break;
default:
System.out.print("***");
}
System.out.println("Done");
}
}
Which modification enables the code fragment to print TrueDone?
A. Replace line 5 With String opt="true";
Replace line 7 with case "true":
B. Replace line 5 with boolean opt=1;
Replace line 7 with case 1:
C. At line 9, remove the break statement.
D. Remove the default section.
정답: A
해설:
switch() 의 괄호 안에는 boolean이 올 수 없고 정수, 스트링 또는 enum만 올 수 있다.
Cannot switch on a value of type boolean. Only convertible int values, strings or enum variables are permitted
그래서 아래처럼 코딩하면 정답이 나온다.
public class Switch13 {
public static void main(String[] args) {
String opt="true";
switch(opt) {
case "true":
System.out.print("True");
break;
default:
System.out.print("***");
}
System.out.println("Done");
}
}
결과:
TrueDone
'ocajp 자격증 (Oracle Certified Associate Ja' 카테고리의 다른 글
자바 ocjap 문제 해설 - 연산자 (0) | 2020.02.24 |
---|---|
자바 ocjap 문제 해설 - do while (0) | 2020.02.24 |
자바 ocjap 문제 해설 - 배열(Array) (0) | 2020.02.23 |
자바 ocjap 문제 및 해설 - 배열 (0) | 2020.02.23 |
자바 ocjap 문제 및 해설 - Exception (0) | 2020.02.23 |
- Total
- Today
- Yesterday
- XE3
- 이클립스
- 파이썬
- 포인터
- esql
- Python
- 인포믹스
- 자바 smtp
- XE
- 프로씨
- 문자열
- webix
- 파싱
- JDBC
- C
- ocjap
- proc
- 플러터
- EC
- MySQL
- ocajp
- 자바
- 라이믹스 모듈
- KG
- 오라클
- xe addon
- xe애드온
- C언어
- php
- 스크래핑
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |