public class Test2 {
public static void main(String[] args) {
Shap s[] = new Shap[3];
s[0] =new Rect(8,0);
s[1] =new Rect(5.0,6.0);
s[2] =new Rect(new Rect(12.0,4.0));
for(int i=0;i<s.length;i++){
System.out.println("s["+i+"]area="+s[i].area());
}// TODO Auto-generated method stub
}
}
abstract class Shap{
private double w,h;
Shap(double i){
w=h=i;
}
Shap(double i,double j){
w = i;
h = j;
}
Shap(Shap s){
w = s.w;
h = s.h;
}
double getw(){
return h;
}
double geth(){
return w;
}
abstract double area();
}
class Rect extends Shap{
Rect(double i){
super(i);
}
Rect(double i,double j){
super(i,j);
}
Rect(Rect r){
super(r);
}
double area(){
return getw()*geth();
}
}谁能帮我分析下这个题 为什么s[2]的结果是48? |