JAVA/소설같은자바

참조 변수끼리의 할당

김컴맹 2011. 8. 12. 12:58
반응형

 
□ 참조를 증명하기 위한 클래스

1
2
3
4
5
6
7
8
9
10
11
12
public class MotorCycle { 
    private int id;
    private int speed;
    public void setData(int i, int s){ 
        id = i;
        speed = s;
    }
    public void drive(){ 
        System.out.println("이 오토바이의 번호판은 " + id + " 입니다.");
        System.out.println("오토바이는 현재 " + speed + " Km 속도로 달립니다.");
    }

□ 메모리 없는 객체 m과 메모리 있는 객체 c의 생성

1
2
 MotorCycle m = null;
 MotorCycle c = new MotorCycle();


□ 참조 변수끼리의 할당(참조값 값복사)

1
2
3
 MotorCycle m = null;
 MotorCycle c = new MotorCycle();
 m = c;

반응형

'JAVA > 소설같은자바' 카테고리의 다른 글

MotorCycle m = new MotorCycle()  (0) 2011.08.12
참조 변수의 타입  (0) 2011.08.12
참조 변수의 특징  (0) 2011.08.08
객체의 메모리 생성  (0) 2011.08.08
private 멤버 필드를 사용하는 이유  (0) 2011.08.08