新手写的!不会改!太逊了!

EdgerLee 2003-03-28 05:12:33
public class Point{
protected int x,y;
Point(int a,int b){setPoint(a,b);}
public void setPoint(int a,int b){
x=a;
y=b;
}
public int getX(){return x;}
public int getY(){return y;}
}

public class Line extends Point{
protected int x,y,endX,endY;
Line(int x1,int y1,int x2,int y2){setLine(x1,y1,x2,y2);}
public void setLine(int x1,int y1,int x2,int y2){
x=x1;
y=y1;
endX=x2;
endY=y2;
}
public int getX(){return x;}
public int getY(){return y;}
public int getEndX(){return endX;}
public int getEndY(){return endY;}
public double length(){
return Math.sqrt((endX-x)*(endX-x)+(endY-y)*(endY-y));
}
}

public class Circle extends Point{
protected int radius;
Circle(int a,int b,int r){
super(a,b);
setRadius(r);
}
public void setRadius(int r){radius=r;}
public int getRadius(){return radius;}
public double area(){return 3.14159*radius*radius;}
}
错误提示:
Point.java:12: class Line is public, should be declared in a file named Line.jav
a
public class Line extends Point{
^
Point.java:30: class Circle is public, should be declared in a file named Circle
.java
public class Circle extends Point{
^
Point.java:14: cannot resolve symbol
symbol : constructor Point ()
location: class Point
Line(int x1,int y1,int x2,int y2){setLine(x1,y1,x2,y2);}
^
3 errors
...全文
45 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
jcq 2003-03-28
  • 打赏
  • 举报
回复
记住super这句一定要放在Line构造的第一句
yzxasd 2003-03-28
  • 打赏
  • 举报
回复
一个文件里可以有多个类,但是只能有一个public
jcq 2003-03-28
  • 打赏
  • 举报
回复
第三个错的原因是:
你Line从Point继承,但是你的Point没有不带参数的构造函数就出错了,改的方法是:
定义一个不带参数的构造,还有就是在Line的构造中使用super(int x1,int y1,int x2,int y2);
ChDw 2003-03-28
  • 打赏
  • 举报
回复
你必须将这两个类分别保存成两个文件
一个文件中只是允许存在一个最外面的类(内部类是存在最外类的内部的)
jcq 2003-03-28
  • 打赏
  • 举报
回复
不要在一个文件中定义多个public的class

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧