[2-8] 참조형 변수(reference type)와 같은 크기의 기본형(primitive type)은? (모두 고르시오)
int
long
short
float
double
풀이
참조형 변수는 64bit JVM을 사용하면 8byte : double
32bit JVM을 사용하면 4byte : int, float
[2-9] 다음 중 형 변환을 생략할 수 있는 것은? (모두 고르시오)
byte b = 10;
char ch = 'A;
int i = 100;
long l = 1000L;
a. b = (byte)i;
b. ch = (char)b;
c. shrot s = (short)ch;
d. float f = (flaot)l;
e. i = (int)ch;
풀이
int(4) → byte(1) 크기가 작기 때문에 불가능
byte(1) → char(2) 음수는 변환 불가능
char(2) → short(2) 크기는 같지만, 음수 변환 불가능
long(8) → float(4) 크기가 작아서 실수 생략 가능하므로 가능
char(2) - int(4) 가능
[2-10] char 타입의 변수에 저장될 수 있는 정수 값의 범위는? (10진수로 적으시오)
풀이
0~65536 = 2^16-1
[2-11] 다음 중 변수를 잘못 초기화 한 것은? (모두 고르시오)
a. byte b = 256;
b. char c = '';
c. char answer = 'no';
d. float f = 3.14
e. double d = 1.4e3f;
풀이
byte : -128~127 불가능
char : 한개의 문자가 아니라 불가능
char : 두개의 문자 불가능
float : 리터럴 뒤에 f가 오지 않아서 불가능
[2-12] 다음 중 main 메서드의 선언부로 알맞은 것은? (모두 고르시오)
a. publicstaticvoid main(String[] args)
b. publicstaticvoid main(String args[])
c. publicstaticvoid main(String[] arv)
d. publicvoidstatic main(String[] args)
e. staticpublicvoid main(String[] args)
풀이
a, b, c, e
[2-13] 다음 중 타입과 기본값이 잘못 연결된 것은? (모두 고르시오)
a. boolean - false
b. char - '\\u0000'// 16진수 저장
c. float - 0.0
d. int - 0
e. long - 0
f. String - ""