New*_*bie 0 java abstract-class
嗨,我想在Eclipse中执行此代码.
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();
}
}
Run Code Online (Sandbox Code Playgroud)
任何人都可以帮助我.为什么我无法将ShapeNew的引用分配给Rect的对象?我收到这个错误
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
Type mismatch: cannot convert from Rect to ShapeNew
Run Code Online (Sandbox Code Playgroud)
你有一个错字:你需要从你定义的类扩展:
class Rect extends ShapeNew {
(另外,看起来你已经实现了一个正方形而不是一个矩形,因为你的面积函数是一个长度).