abstract class Shape
{
abstract float area();
}
class Rectangle extends Shape
{
public float width,height;
Rectangle (float w, float h)
{
width = w; // 这里不需 "this"
height = h;
}
public float area()
{
return width*height;
}
}
class Circle extends Shape
{
public float r;
Circle(float r)
{
this.r = r; //this 指 " 这个对象的 "
}
public float area()
{
return 3.14*r*r;
}
}
Java 中的抽象类、接口和程序包
—— 抽象类与抽象方法