array 에서 final 의 의미 (다시 !!)


[ 다음 글들 ] [ 이어서 글올리기(답하기) ] [ 자바 묻고 답하기 ]

글쓴이 :김필호 1999년 10월 12일 11:09:51

In Reply to: static initializer 블록을 사용하면 되겠네요... posted by 윤경구 on 1999년 10월 11일 22:22:27:


static final int[] array = new int[10];


로 선언하면 변수 array 는 final 이지만,
array[0], array[1], ... , array[9] 들은 final 이 아닙니다.



class FinalArrayTest {
static final int[] array = new int[10];


public static void main(String[] args) {
for (int i=0; i<10; i++)
array[i] = (int) (Math.random()*1000);
for (int i=0; i<10; i++)
System.out.println(array[i] + ", ");
System.out.println();


array[9] = 999;
System.out.println("Last member changed: ------------");
for (int i=0; i<10; i++)
System.out.println(array[i] + ", ");
Sstem.out.println();
}
}





다음 글들:



이어서 글올리기(답하기)

이름:
E-Mail:
제목:
내용:
HTML 태그 포함 여부: HTML 문서일 경우 체크
관련 URL(선택):
URL 제목(선택):
관련 이미지 URL:


[ 다음 글들 ] [ 이어서 글올리기(답하기) ] [ 자바 묻고 답하기 ]