当前位置: 代码迷 >> Java相关 >> [求助]java中接口做参数的这几句代码是什么意思?
  详细解决方案

[求助]java中接口做参数的这几句代码是什么意思?

热度:324   发布时间:2007-11-02 22:04:41.0
[求助]java中接口做参数的这几句代码是什么意思?
interface computerable
{public double 求面积();
class 梯形 implementes computerable
{ double a,b,h;
梯形(double a,double b,double h)
{this.a=a;
this.b=b;
this.h=h;
}
public double 求面积 ()
{return((1/2.0)*(a+b)*h);}
}
class 圆形 implementes computerable
{ double r
圆形(double r)
{this.r-=r;

}
public double 求面积 ()
{return(3.14*r*r);}
}
class 堆
{ computerable 底;
double 高;

堆(computerable 底,double 高)
{this.底=底;
this.高=高;
}
void 换底 (computerable 底)

{this.底=底;}
public double 求体积()
{return(底.求体积()*高/3.0);}
}
public class E
{
public static void main(string args[])
{堆 zui;
computerable bottom;
bottom=new 梯形(2.0,7.0,10.0);
system.out.print("梯形的面积"+bottom.求面积());
zui =new 堆 (bottom,30);
system.out.print("梯形的体积"+zui.求体积());
bottom=new 圆形(10);
system.out.print("半径是10的圆的面积:"bottom.求面积());
zui.换底(bottom);
system.out.print("圆形底的堆的体积:"zui.求体积());
}
}
帮我解释一下,接口做参数的用法?
就是class 堆
{ computerable 底;
double 高;

堆(computerable 底,double 高)
{this.底=底;
this.高=高;
}
void 换底 (computerable 底)

{this.底=底;}
public double 求体积()
{return(底.求体积()*高/3.0);}
}
public class E
{
public static void main(string args[])
{堆 zui;
computerable bottom;
bottom=new 梯形(2.0,7.0,10.0);
system.out.print("梯形的面积"+bottom.求面积());
zui =new 堆 (bottom,30);
system.out.print("梯形的体积"+zui.求体积());
bottom=new 圆形(10);
system.out.print("半径是10的圆的面积:"bottom.求面积());
zui.换底(bottom);
system.out.print("圆形底的堆的体积:"zui.求体积());
}
}
搜索更多相关的解决方案: java  接口  参数  代码  

----------------解决方案--------------------------------------------------------
  相关解决方案