abstract class Geometry
{
public abstract double ComputerArea();
}
class Lader extends Geometry
{
double a,b,h;
Lader(double a,double b,double h)
{
this.a=a;this.b=b;this.h=h;
}
public double ComputerArea()
{
return((1/2.0)*(a+b)*h);
}
}
class Circle extends Geometry
{
double r;
Circle(double r)
{
this.r=r;
}
public double ComputerArea()
{
return(3.14*r*r);
}
}
class Cone
{
Geometry bottom;
double height;
Cone(Geometry bottom,double height)
{
this.bottom=bottom;
this.height=height;
}
void changBottom(Geometry bottom)
{
this.bottom=bottom;
}
public double ComputerVolume()
{
return (bottom.ComputerArea()*height)/3.0;
}
}
public class Example
{
public static void main(String args[])
{
Cone cone;
Geometry geometry;
geometry=new Lader(2.0,7.0,10.7);
System.out.println("梯形的面积"+geometry.ComputerArea()--?);
cone=new Cone(geometry,30);
System.out.println("梯形底的锥的体积"+cone.ComputerVolume());
geometry=new Circle(10);
System.out.println("半径是10的圆的面积"+geometry.ComputerArea()--?);
cone.changBottom(geometry);
System.out.println("圆形底的锥的体积"+cone.ComputerVolume());
}
}
虽然是个java的例子,但是道理是一样的,想问一下,接口可以回调,但抽象类不允许回调,但以上这个例子不是一种回调吗?谢谢
{
public abstract double ComputerArea();
}
class Lader extends Geometry
{
double a,b,h;
Lader(double a,double b,double h)
{
this.a=a;this.b=b;this.h=h;
}
public double ComputerArea()
{
return((1/2.0)*(a+b)*h);
}
}
class Circle extends Geometry
{
double r;
Circle(double r)
{
this.r=r;
}
public double ComputerArea()
{
return(3.14*r*r);
}
}
class Cone
{
Geometry bottom;
double height;
Cone(Geometry bottom,double height)
{
this.bottom=bottom;
this.height=height;
}
void changBottom(Geometry bottom)
{
this.bottom=bottom;
}
public double ComputerVolume()
{
return (bottom.ComputerArea()*height)/3.0;
}
}
public class Example
{
public static void main(String args[])
{
Cone cone;
Geometry geometry;
geometry=new Lader(2.0,7.0,10.7);
System.out.println("梯形的面积"+geometry.ComputerArea()--?);
cone=new Cone(geometry,30);
System.out.println("梯形底的锥的体积"+cone.ComputerVolume());
geometry=new Circle(10);
System.out.println("半径是10的圆的面积"+geometry.ComputerArea()--?);
cone.changBottom(geometry);
System.out.println("圆形底的锥的体积"+cone.ComputerVolume());
}
}
虽然是个java的例子,但是道理是一样的,想问一下,接口可以回调,但抽象类不允许回调,但以上这个例子不是一种回调吗?谢谢
解决方案 »
- c#网络通信问题 服务器只能接收一次信息
- ExecWB打印的时候如何能不打印当前页面的地址
- Socket实现HTTP协议的相关问题,急!
- 如何获得一个字符串的象素?
- 如何使用特性在编译时给出警告和消息?
- 请问,使用 remoting 做IM有没有可行性?
- 求助!!!听说C# Network Programming这本书不错!
- 我想用SqlDataReader取出sql表中的varBinary形数据并转换成int 形.并进行与运算,但试了很久都没有成功,(转换不了)有没有那位试过,并指点
- excel问题
- 如何知道纸张类型名称,获取纸张大小
- gridview 标题栏固定 ?????
- 为什么总是说“无法将类型"string"转换为"char"”?
只是在C#中只能继承一个类,但可以继承多个接口,所以用接口实现更多罢了!我是这样理解的!
那位大侠给写个demo.......
我现在 web service 回调客户端实现接口的那个方法的时候报异常..........