嗨我想在Eclipse中执行此代码。java抽象类的用法
abstract class ShapeNew {
int length;
public abstract double area();
}
class Rect extends Shape{
Rect(int side){
this.length = side;
}
public double area(){
System.out.println("area of rectangle"+ length*length);
return length*length;
}
/**
* @param args
*/
public static class Area{
public static void main(String[] args) {
// TODO Auto-generated method stub
ShapeNew rect = new Rect(32);// I am unable to use this. The eclipse throws an error//
rect.area();
}
}
任何人都可以帮助我。为什么我无法将ShapeNew的引用分配给Rect的对象? 我得到这个错误
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
Type mismatch: cannot convert from Rect to ShapeNew
正如在这里的各种答案解释你有一个类型。将Shape更改为ShapeNew(虽然我会使用更好的类名)。 – Atul