기본형 매개변수

essential·2023년 5월 25일

객체 지향

목록 보기
10/40

기본형 매개 변수

  • 변수의 값을 읽기만 할 수 있다. (read only)

참조형 매개 변수

  • 변수의 값을 읽고 변경할 수 있다 (read & write)
class Data { int x; }

class Ex6_6 {
	public static void main(String[] args) {
		Data d = new Data(); //객체생성
		d.x = 10; 
		System.out.println("main() : x = " + d.x);

		change(d.x);
		System.out.println("After change(d.x)");
		System.out.println("main() : x = " + d.x);
	}

	static void change(int x) {  // 기본형 매개 변수
		x = 1000;
		System.out.println("change() : x = " + x);
	}
}

** 지역변수 x = 1000 인 게 중요

= chang(d.x) 는 출력값이 1000

= System.out.println("main() : x = " + d.x); 10

profile
essential

0개의 댓글