Program/Java Programming

대입연산자(=)

Hue Kim 2012. 9. 23. 03:50

대입연산자 = 를 사용하여 한객체를 다른 객체에 할당할 수도 있다.


import java.awt.*;

class ObjRef {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Point pt1, pt2;
		pt1 = new Point(100, 150);
		pt2 = new Point(200, 250);
		System.out.println("pt1 : " + pt1.x + "." + pt1.y);
		System.out.println("pt2 : " + pt2.x + "." + pt2.y);

		pt2 = pt1;
		System.out.println("pt1 : " + pt1.x + "." + pt1.y);
		System.out.println("pt2 : " + pt2.x + "." + pt2.y);

		pt1.x = 300;
		pt1.y = 350;
		System.out.println("pt1 : " + pt1.x + "." + pt1.y);
		System.out.println("pt2 : " + pt2.x + "." + pt2.y);
	}

}

pt1 : 100.150

pt2 : 200.250

pt1 : 100.150

pt2 : 100.150

pt1 : 300.350

pt2 : 300.350