返回信息流在网上找很久,还是没搞懂这个编译错误的根源,求教
源代码如下:
public class Point{
protected int x,y;
public Point(){setPoint(0,0);}
public 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 String toString(){return "[" + x +"," + y + "]";}
}
public class Circle extends Point{
protected double radius;
public Circle(){setRadius(0);}
public void Cricle(double r ,int a , int b){setRadius(r);super(a,b);}
public void setRadius (double r){radius=(r>=0 ? r:0);}
public double getRadius() {return radius;}
public double area(){return Math.PI * Math.pow(radius);}
public String toString(){return "Center = " + super.toString() + "; Radius = "+radius;}
}
public class Cylinder extends Circle{
protected double height;
public Cylinder(){setheight(0);}
public Cylinder(double h ,double r,int a , int b){super(r,a,b);setheight(h);}
public void setheight(double h){height=h;}
public double getheight(){return height;}
public double area()
{
return 2 * super.area()+2*Math.PI*radius*height;
}
public double volume(){return super.area*height;}
public String toString()
{
return super.toString()+": Height = "+height;
}
}
import javax.swing.JOptionPane;
import java.text.DecimalFormat;
public class Test{
public static void main(String args[]){
Cylinder c = new Cylinder(5.7 , 2.5 , 12 , 23);
DecimalFormat precision2 = new DecimalFormat("0.00");
String output;
output= "X coordinate is " +c.getX() +
"\nY corrdinate is "+c.getY() +
"\nRadius coordinate is "+c.getRadius() +
"\nHeight coordinate is "+c.getheight();
c.setheight(10);
c.segRadius(4.25);
c.setPoint(2,2);
output +="\n\nThe new location, radius "+
"and height of c are\n"+ c +
"\nArea is "+ precision2.format(c.area())+
"\nVolume is "+ precision2.format(c.volume());
JOptionPane.showMessageDialog(null,output,"Demonstrating ClassCylinder",JOptionPane.INFORMATION_MESSAGE);
System.exit(0);
}
}
报错的截图在下面
这是一条镜像帖。来源:北邮人论坛 / java / #13398同步于 2010/3/9
该镜像源已超过 30 天没有更新,可能在源站已被删除。
Java机器人发帖
求助"需要为class、interface或enum 。。。"
nature1089
2010/3/9镜像同步4 回复
订阅后,新回复会通过你的通知中心匿名送达。
4 条回复
这个是修改过的代码。lz不认真呀,好几个细节错误!另外,一个.java中最好只一个public 类,不然编绎器不知道从哪个类进入。还有,super()一定要在够造函数第一句!
import javax.swing.JOptionPane;
import java.text.DecimalFormat;
class Point{
protected int x,y;
public Point(){setPoint(0,0);}
public 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 String toString(){return "[" + x +"," + y + "]";}
}
class Circle extends Point{
protected double radius;
public Circle(){setRadius(0);}
public Circle(double r ,int a , int b){super(a,b);setRadius(r);}
public void setRadius (double r){radius=(r>=0 ? r:0);}
public double getRadius() {return radius;}
public double area(){return Math.PI * Math.pow(radius,2);}
public String toString(){return "Center = " + super.toString() + "; Radius = "+radius;}
}
class Cylinder extends Circle{
protected double height;
public Cylinder(){setheight(0);}
public Cylinder(double h ,double r,int a , int b){super(r,a,b);setheight(h);}
public void setheight(double h){height=h;}
public double getheight(){return height;}
public double area()
{
return 2 * super.area()+2*Math.PI*radius*height;
}
public double volume(){return super.area()*height;}
public String toString()
{
return super.toString()+": Height = "+height;
}
}
public class Test{
public static void main(String args[]){
Cylinder c = new Cylinder(5.7 , 2.5 , 12 , 23);
DecimalFormat precision2 = new DecimalFormat("0.00");
String output;
output= "X coordinate is " +c.getX() +
"\nY corrdinate is "+c.getY() +
"\nRadius coordinate is "+c.getRadius() +
"\nHeight coordinate is "+c.getheight();
c.setheight(10);
c.setRadius(4.25);
c.setPoint(2,2);
output +="\n\nThe new location, radius "+
"and height of c are\n"+ c +
"\nArea is "+ precision2.format(c.area())+
"\nVolume is "+ precision2.format(c.volume());
JOptionPane.showMessageDialog(null,output,"Demonstrating ClassCylinder",JOptionPane.INFORMATION_MESSAGE);
System.exit(0);
}
}