ocajp 자격증 (Oracle Certified Associate Ja

자바 ocjap 문제 해설 - 배열(Array)

xemaker 2020. 2. 23. 20:40

Given the code fragment:

package ocjap;
public class Arr18 {
public static void main(String[] args) {
/* insert code here */
int array[2];
array[0]=10;
array[1]=20;
System.out.print(array[0]+":"+array[1]);

}

}

Which code fragment, when inserted at line 3, enables the code to print 10:20?

A. int[] array=new int[2];

B. int[] array;

array=int[2];

C. int array=new int[2];

D. int array[2];

 

정답: A

해설:

자바의 배열 선언방법

B번은 아래와 같은 오류가 발생.

The type of the expression must be an array type but it resolved to Class

C번 오류

Type mismatch: cannot convert from int[] to int

D번 오류

Syntax error on token "2", delete this token