日期:2014-05-17  浏览次数:21068 次

Unresolved compilation problems: Cannot instantiate the type Rectangle
package exit5;

public class testabstract {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
  Shape shape1,shape2;
  shape1=new Rectangle(10.0,20.0);
  shape1.showarea();
shape2=new Circle(10.0);
  shape2.showarea();
  shape2.resize(0.2);
  shape2.showarea();
}

}package exit5;

public abstract class Rectangle extends Shape {
  double w,h;
  public Rectangle(double h0 ,double w0) {
// TODO Auto-generated constructor stub
h=h0;w=w0;
}
  double getarea(){
return h*w;
  }
  void resize(double factor){
w*=factor;h*=factor;
  }
}


------解决方案--------------------
abstract class couldn't be instance.