[자바의 정석]기본형 매개변수

이혜수·2023년 2월 27일
0

기본형 매개변수 : 변수의 값을 읽기만 할 수 있다(read only), 변경불가

예제 >

class Data{ int x; }

public 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);    // change 의 지역변수 값 x
	}

}

point!!!! change의 지역변수값 x를 바꾸는 것!

결과 값

profile
성장하는 땅콩개발자 :)

0개의 댓글