/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package yuan;
public class Yuan {
double x;
double y;
double r;
public Yuan(double x, double y,double r)
{
this.x=x;
this.y=y;
this.r=r;
}
public void setPerimeter(double c)
{
c=2*r*r*Math.PI;
}
public double getPerimeter(double c)
{
return c;
}
public void setArea(double s)
{
s=Math.PI*r*r;
}
public double getArea(double s)
{
return s;
}
}
public class Yuanzhu extends yuan
{
protected double h;
protected double a;
protected double b;
double Area,Volume;
public Yuanzhu(double x,double y,double r)
{
super(x,y,r);
}
public void seth(double h)
{
h=h;
}
public double geth(double h)
{
return h;
}
public void setArea(double h,double r)
{
a=4*r*r*Math.PI+h*Math.PI*r*r;
}
public double getArea(double a)
{
return a;
}
public void setVolume(double h,double r)
{
b=h*Math.PI*r*r;
}
public double getVolume(double b)
{
return b;
}
public void print()
{
System.out.println("表面积是"+a);
System.out.println("体积是"+b);
}
public static void main(String args[])
{
Yuanzhu t;
t=new Yuanzhu(3,4,5);
t.print();
}
}
亲发现你几个小问题。
1 public class Yuanzhu extends yuan 这句有两个错误 一个文件只能有一个public 类 Yuanzhu 继承与Yuan 首字母要大写。哦,那是不是把子类前面的public 去掉就好了呢?我去试试
追答en 不知道 我没试 你自己试试 有问题我再给你解决
追问呃,再麻烦下,我现在解决了报错问题,并且把main函数放到了 public 括号里了 ,能运行,但是结果都显示为0.0 这是怎么回事呢?
追答问题解决了吗 没解决的话 我就看看 要是解决了 我也省事了