这恐怕是你的构造函数没有加上public的原因

解决方案 »

  1.   

    static方法不可以访问非static的东东
    改:import java.io.PrintWriter;
    class PointTest
    {
    public class Point2D //¶¨ÒåPoint2DÀà
    {
    int x,y;
    Point2D() //¶¨ÒåPoint2D·½·¨
    {
    this (0,0);
    }
    Point2D (int x)
    {
    this (x,0);
    }
    Point2D (int x,int y)
    {
    this.x = x;
    this.y = y;
    }
    double length()
    {
    return Math.sqrt(x * x + y * y); //Çóƽ·½¸ùº¯Êý(sqrt)
    }
    }
    public class MyPoint extends Point2D //Éú³É¼Ì³ÐÀàPoint2D
    {
    int x,y;
    MyPoint (int x,int y) {
    super (x,y);
    this.x = x;
    this.y = y;
    }
    double length() {
    return Math.sqrt (x * x + y * y);
    }
    double distance() {
    return Math.abs (length() - super.length());
    }
    }
    public static void main (String args[]) 
    {
      new PointTest();
    } public PointTest() {
    PrintWriter out = new PrintWriter (System.out,true);
    MyPoint mp = new MyPoint(4,3);
    Point2D p = new Point2D(11);
    Point2D q = mp;
    mp.x = 5;
    mp.y = 12;
    out.println("\n\tDataMember Access Test:\n");
    out.println("mp = (" + mp.x + "," + mp.y + ")");
    out.println("p = (" + p.x + "," + p.y + ")");
    out.println("q = (" + q.x + "," + q.y + ")");
    out.println("\n\tCasttingTest:\n");
    out.println("(Point2D)mp = (" + ((Point2D)mp).x + "," + ((Point2D)mp).y + ")");
    out.println("(MyPoint)q = (" + ((MyPoint)q).x + "," + ((MyPoint)q).y + ")");
    out.println("\n\tMethodMember Access Test:n");
    out.println("mp.length() = " + mp.length());
    out.println("p.length() = " + p.length());
    out.println("q.length() = " + q.length());
    out.println("mp.distance() = " + mp.distance());
    out.println("\n\tCasting Test:\n");
    out.println("((Point2D)mp).length() = " + ((Point2D)mp).length());
    out.println("((Point2D)q).length() = " + ((Point2D)q).length());
    out.println("((MyPoint)q).distance() = " + ((MyPoint)q).distance());
    }
    }
      

  2.   

    非静态内部类和其他非静态成员一样,不能直接被main之内的静态成员使用
      

  3.   

    paste出来出了点问题,重贴import java.io.PrintWriter;
    class PointTest
    {
      public class Point2D //定义Point2D类
      {
        int x,y;
        Point2D() //定义Point2D方法
        {
          this (0,0);
        }
        Point2D (int x)
        {
          this (x,0);
        }
        Point2D (int x,int y)
        {
          this.x = x;
          this.y = y;
        }
        double length()
        {
          return Math.sqrt(x * x + y * y); //求平方根函数(sqrt)
        }
      }
      public class MyPoint extends Point2D //生成继承类Point2D
      {
        int x,y;
        MyPoint (int x,int y) {
          super (x,y);
          this.x = x;
          this.y = y;
        }
        double length() {
          return Math.sqrt (x * x + y * y);
        }
        double distance() {
          return Math.abs (length() - super.length());
        }
      }
      public static void main (String args[]) 
      {
        new PointTest();
      }  public PointTest() {
        PrintWriter out = new PrintWriter (System.out,true);
        MyPoint mp = new MyPoint(4,3);
        Point2D p = new Point2D(11);
        Point2D q = mp;
        mp.x = 5;
        mp.y = 12;
        out.println("\n\tDataMember Access Test:\n");
        out.println("mp = (" + mp.x + "," + mp.y + ")");
        out.println("p = (" + p.x + "," + p.y + ")");
        out.println("q = (" + q.x + "," + q.y + ")");
        out.println("\n\tCasttingTest:\n");
        out.println("(Point2D)mp = (" + ((Point2D)mp).x + "," + ((Point2D)mp).y + ")");
        out.println("(MyPoint)q = (" + ((MyPoint)q).x + "," + ((MyPoint)q).y + ")");
        out.println("\n\tMethodMember Access Test:n");
        out.println("mp.length() = " + mp.length());
        out.println("p.length() = " + p.length());
        out.println("q.length() = " + q.length());
        out.println("mp.distance() = " + mp.distance());
        out.println("\n\tCasting Test:\n");
        out.println("((Point2D)mp).length() = " + ((Point2D)mp).length());
        out.println("((Point2D)q).length() = " + ((Point2D)q).length());
        out.println("((MyPoint)q).distance() = " + ((MyPoint)q).distance());
      }
    }
      

  4.   

    用new PointTest().new MyPoint(4,3)的形式构造实例
    或把内部类改成static
      

  5.   

    这个是新的问题:
    Exception in thread "main" java.lang.NoClassDefFoundError: PointClass1/java
      

  6.   

    java PointClass1
    不要加.java
      

  7.   

    源程序
    import java.io.PrintWriter;
    public class Point2D //定义Point2D类
    {
    int x,y;
    Point2D() //定义Point2D方法
    {
    this (0,0);
    }
    Point2D (int x)
    {
    this (x,0);
    }
    Point2D (int x,int y)
    {
    this.x = x;
    this.y = y;
    }
    double length()
    {
    return Math.sqrt(x * x + y * y); //求平方根函数(sqrt)
    }
    }
    public class MyPoint extends Point2D //生成继承类Point2D
    {
    int x,y;
    MyPoint (int x,int y) {
    super (x,y);
    this.x = x;
    this.y = y;
    }
    double length() {
    return Math.sqrt (x * x + y * y);
    }
    double distance() {
    return Math.abs (length() - super.length());
    }
    }
    public class PointTest
    {
    public static void main (String args[]) 
    {
    PrintWriter out = new PrintWriter (System.out,true);
    MyPoint mp = new MyPoint(4,3);
    Point2D p = new Point2D(11);
    Point2D q = mp;
    mp.x = 5;
    mp.y = 12;
    out.println("\n\tDataMember Access Test:\n");
    out.println("mp = (" + mp.x + "," + mp.y + ")");
    out.println("p = (" + p.x + "," + p.y + ")");
    out.println("q = (" + q.x + "," + q.y + ")");
    out.println("\n\tCasttingTest:\n");
    out.println("(Point2D)mp = (" + ((Point2D)mp).x + "," + ((Point2D)mp).y + ")");
    out.println("(MyPoint)q = (" + ((MyPoint)q).x + "," + ((MyPoint)q).y + ")");
    out.println("\n\tMethodMember Access Test:n");
    out.println("mp.length() = " + mp.length());
    out.println("p.length() = " + p.length());
    out.println("q.length() = " + q.length());
    out.println("mp.distance() = " + mp.distance());
    out.println("\n\tCasting Test:\n");
    out.println("((Point2D)mp).length() = " + ((Point2D)mp).length());
    out.println("((Point2D)q).length() = " + ((Point2D)q).length());
    out.println("((MyPoint)q).distance() = " + ((MyPoint)q).distance());
    }
    }
    执行的结果
    PointClass.java:2: 类 Point2D 是 公共的(public〕,应该在名为 Point2D.java 的文
    件中被声明
            public class Point2D                            //定义Point2D类
                   ^
    PointClass.java:23: 类 MyPoint 是 公共的(public〕,应该在名为 MyPoint.java 的文
    件中被声明
            public class MyPoint extends Point2D                    //生成继承类Poin
    t2D
                   ^
    PointClass.java:38: 类 PointTest 是 公共的(public〕,应该在名为 PointTest.java
    的文件中被声明
            public class PointTest
                   ^
    3 个错误
    我已声明的了???
      

  8.   

    在第4行定义Point2D类语句中加入static
    即:public static class Point2D
    在第25行定义生成继承类Point2D语句中加入static
    即:public static class MyPoint extends Point2D