Tag: 类超类

为什么java多态性不能在我的例子中工作

我有这4个java clases:1 public class Rect { double width; double height; String color; public Rect( ) { width=0; height=0; color="transparent"; } public Rect( double w,double h) { width=w; height=h; color="transparent"; } double area() { return width*height; } } 2 public class PRect extends Rect{ double depth; public PRect(double w, double h ,double d) { width=w; height=h; […]