2 回答
MMTTMM
TA贡献1869条经验 获得超4个赞
public interface Graph
{
public double volume();
}
//圆柱
public class Cylinder implements Graph
{
private double radius;
public Cylinder(double radius) {
this.radius = radius;
}
@Override
public double volume()
{
//计算体积公式
return 0;
}}
//长方
public class Cuboid implements Graph
{
private double width;
private double height;
private double length;
public Cuboid(double width, double height, double length)
{
this.width = width;
this.height = height;
this.length = length;
}
@Override
public double volume()
{
// 公式
return 0;
}}
//工具
public class ComputeUtil
{
public static double computeVolume(Graph graph) {
return graph.volume();
}
}
慕田峪9158850
TA贡献1794条经验 获得超8个赞
关于重载,可以参照下面的代码:
[code="java"]public class Volumn{
//球体体积
public float computeVolumn(float radius){
}
//圆柱体体积
public float computeVolumn(float radius, float height){
}
//长方体体积(包括立方体)
public float computeVolumn(float length, float width, float height){
}
添加回答
举报
0/150
提交
取消
