Java/Constructor (생성자)
참조 호출 Call by reference
Bohemian life
2012. 4. 11. 13:22
class MyDate{//참조 호출 call by reference int year=2006; int month=4; int day=1; } class RefMethod{ void changeDate(MyDate t){ t.year=2007; t.month=7; t.day=19; } } public class MethodTest09 { public static void main(String[] args){ RefMethod rm = new RefMethod(); MyDate d=new MyDate(); //각 각 클래스 메모리에 올리기 System.out.println("함수 호출전 d-> "+d.year+"/" +d.month+ "/" +d.day); rm.changeDate(d); //주소를 MyDate t로 넘기기 //t는 MyDate클래스의 안에 객체로 넘어감 //int대신 MyDate가 오면 참조자료형이 오면은 값이 아닌 주소가 오게됨 System.out.println("함수 호출전 d-> "+d.year+"/" +d.month+ "/" +d.day); } }
함수 호출전 d-> 2006/4/1
함수 호출전 d-> 2007/7/19