2012年6月19日10:08:02
源碼:
/**
* demo
*/
package demo;
/**
* @author Wu Zhenzhen
* @version Jun 19, 2012 10:02:07 AM
*
*/
public class Point
{
private int x;
private int y;
public void move(int x, int y)
{
this.x += x;
this.y += y;
}
@Override
public String toString()
{
return "Point [x=" + x + ", y=" + y + "]";
}
/**
* @param x
* @param y
*/
public Point(int x, int y)
{
super();
this.x = x;
this.y = y;
}
/**
*
*/
public Point()
{
super();
}
}
/**
* demo
*/
package demo;
/**
* @author Wu Zhenzhen
* @version Jun 19, 2012 10:03:50 AM
*
*/
public class TestPoint
{
/**
* <p />
* Jun 19, 2012 10:03:50 AM
*
* @param args
*/
public static void main(String[] args)
{
Point p1 = new Point(1, 1);
Point p2 = p1;
System.out.print("P1 ===> ");
System.out.println(p1);
System.out.print("P2 ===> ");
System.out.println(p2);
System.out.println("=============================");
p2.move(10, 10);
System.out.print("P1 ===> ");
System.out.println(p1);
System.out.print("P2 ===> ");
System.out.println(p2);
}
}
結果:
P1 ===> Point [x=1, y=1]
P2 ===> Point [x=1, y=1]
=============================
P1 ===> Point [x=11, y=11]
P2 ===> Point [x=11, y=11]