abstract class Point
{
double x;
double y;
abstract double S();
abstract double V();
}
class Circle extends Point
{
double x;
double y;
double radius;
public Circle(double x,double y)
{
this.x=x;
this.y=y;
}
public void setXY(double x,double y)
{
this.x=x;
this.y=y;
}
public void setRadius()
{
this.radius=Math.sqrt(x*x+y*y);
}
public double getRadius()
{
return radius;
}
public double S()
{
return radius*radius*Math.PI;
}
public double V()
{
return 0;
}
}
class Ball extends Point
{
double x;
double y;
double radius;
public Ball(double x,double y)
{
this.x=x;
this.y=y;
}
public void setXY(double x,double y)
{
this.x=x;
this.y=y;
}
public void setRadius()
{
this.radius=Math.sqrt(x*x+y*y);
}
public double getRadius()
{
return radius;
}
public double S()
{
return 4*Math.PI*radius*radius;
}
public double V()
{
return (3/4)*Math.PI*radius*radius*radius;
}
}
class Cylinder extends Point
{
double x;
double y;
double radius;
int height;
public Cylinder(double x,double y)
{
this.x=x;
this.y=y;
}
public void setXY(double x,double y)
{
this.x=x;
this.y=y;
}
public void setRadius()
{
radius=Math.sqrt(this.x*this.x+this.y*this.y);
}
public double S()
{
return (Math.PI*radius*radius*2)+(2*Math.PI*radius);
}
public double V()
{
return Math.PI*radius*radius*height;
}
}
public class a2
{
public static void main(String[] args)
{
Ball a=new Ball(3,4);
System.out.println(a.x);
System.out.println(a.y);
System.out.println(a.radius);
a.getRadius();
Cylinder b=new Cylinder(6,8);
System.out.println(a.S());
System.out.println(a.V());
System.out.println(b.S());
System.out.println(b.V());
}
}
运行结果radius的值一直是0
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
4条回答 默认 最新
- CSDN专家-赖老师(软件之家) 2021-04-27 21:31关注
创建对象以后,你要先调用setRadius方法,再调用其他函数就正常了。
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 1无用
悬赏问题
- ¥15 使用C#,asp.net读取Excel文件并保存到Oracle数据库
- ¥15 C# datagridview 单元格显示进度及值
- ¥15 thinkphp6配合social login单点登录问题
- ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
- ¥15 如何在scanpy上做差异基因和通路富集?
- ¥20 关于#硬件工程#的问题,请各位专家解答!
- ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
- ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
- ¥30 截图中的mathematics程序转换成matlab
- ¥15 动力学代码报错,维度不匹配