Call
자바는 call by value와 call by reference 중 무엇인가요?
call by value와 call by reference 의 차이 예시를 코드를 통해 보여주세요.
public class Main {
public static void main(String[] args) {
int value = 5;
callByValue(value);
System.out.println("value = " + value); //value = 5
int[] ref = {5};
callByRef(ref);
System.out.println("ref[0] = " + ref[0]); //ref[0] = 6
}
private static void callByValue(int value) {
value++;
}
private static void callByRef(int[] ref) {
ref[0]++;
}
}참고
Last updated