본문 바로가기
##JAVA

JAVA 기초 TEST 1

by 운중동토토로 2024. 10. 24.

1. 접근제한자(Access modifier) 각각의 접근 가능범위를 간략하게 기술하시오. 

        ① public      ( 클래스 내부, 동일패키지, 상속 받은 클래스, 이외의 영역 ) 

        ② protected ( 클래스 내부, 동일패키지, 상속 받은 클래스 ) 

        ③ default     ( 클래스 내부, 동일패키지 )  

        ④ private     ( 클래스 내부 ) 

 

2. 클래스에 상수 필드 NUM 을 선언하고 초기값 100 으로 초기화하는 구문을 작성하시오. 

        ( 선언과 동시에 초기화 final int NUM = 100; 또는 선언 후 초기화 final int NUM; NUM=100; )

 

3. 아래 소스 코드의 컴파일 및 실행 결과는? ( 8 )

 

public class SwitchExample {
public static int switchIt(int x) {
int j=1;
switch (x){
case 1: j++;
case 2: j++;
case 3: j++;
case 4:j++;
case 5: j++;
default : j++;
}
return j + x;
}

public static void main(String[] args){
System.out.println(switchIt(4));
}
}