唉,看看jdk的源代码,写得很清楚

解决方案 »

  1.   

    写一个简单的吧:
    class Point {
      int x=0;
      int y=0;  Point() {
        x=0;
        y=0;
      }  Point(int xx, int yy) {
        x=xx;
        y=yy;
      }  int getX() {
        return x;
      }
      void setX(int _x) {
        x=_x;
      }  int getY() {
        return y;
      }
      void setY(int _y) {
        y=_y;
      }
    }public class TestPoint {
      public static void main(String[] args) {
        Point a = new Point();
        Point b = new Point(1, 2);    System.out.println("a.x=" + a.x + " a.y=" + a.y);
        System.out.println("b.x=" + b.x + " b.y=" + b.y);    b.setX(3);
        b.setY(4);
        System.out.println("b has changed:");
        System.out.println("b.x=" + b.x + " b.y=" + b.y);
      }
    }