본문 바로가기

카테고리 없음

[JAVA]변수의 유효범위 예제

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
 
package org.opentutorials.javatutorials.scope;
 
public class ScopeDemo6 {
    static int i = 5;
 
    static void a() {
        int i = 10;
        b();
    }
 
    static void b() {
        System.out.println(i);
    }
 
    public static void main(String[] args) {
        a();
    }
 
}
cs


변수의 유효범위에 대한 예제입니다. 

해당 소스를 실행 했을때 출력되는 숫자는 5일까요 10일까요?

출처:https://opentutorials.org