有main方法的那个类必须是public的

解决方案 »

  1.   

    import java.awt.*;class Point {
        private int x = 0;
        private int y = 0;    public Point() {    }
        public Point(int x, int y) {
            this.x = x;
            this.y = y;
        }
        public boolean equals(Object o) {
            if (!(o instanceof Point))return false;
            Point p = (Point)o;
            return p.x == x && p.y == y;
        }
    }class ColorPoint extends Point {
        private Point point;
        private Color color;
        public ColorPoint(int x, int y, Color color) {
            point = new Point(x, y);
            this.color = color;
        }
        public Point asPoint() {
            return point;
        }
        public boolean equals(Object o) {
            if (!(o instanceof ColorPoint))return false;
            ColorPoint cp = (ColorPoint)o;
            return cp.point.equals(point) && cp.color.equals(color);
        }
    }class PointTest{
        public static void main(String[] str){
            Point p=new Point(1,2);
            ColorPoint cp1=new ColorPoint(1,2,Color.RED);
            ColorPoint cp2=new ColorPoint(1,2,Color.BLUE);
            System.out.println(cp1.equals(p));
            System.out.println(p.equals(cp1));
            System.out.println(p.equals(cp2));
            System.out.println(cp1.equals(cp2));
        }
    }自己看看
      

  2.   

    可以编译啊,我在dos下面直接编译是可以的啊
    只不过编译不过而已
    呵呵!
      

  3.   

    class Point {
        private final int x;  // private int x;
        private final int y;  // private int y; 你试一下
        
        public Point(int x, int y) {
            this.x = x;
            this.y = y;
        }    
        public boolean equals(Object o) {
            if (!(o instanceof Point))return false;
            Point p = (Point)o;
            return p.x == x && p.y == y;
        }
    }
      

  4.   

    是因为我将Point类曾经单独编译了一次,导致当前目录里有了Point.class,从而导致错误的调用,换到一个空目录一切ok,谢谢各位,结贴!!