Java 中的接口与嵌套类型深入解析
1. 接口基础
在 Java 中,接口是一种非常重要的概念。接口可以被部分实现,为后续的实现提供一个有用的起点。例如下面这个 AbstractRectangularShape 类部分实现了 RectangularShape 接口:
// Here is a partial implementation of that interface. Many
// implementations may find this a useful starting point.
public abstract class AbstractRectangularShape implements RectangularShape {
// The position and size of the shape
protected double x, y, w, h;
// Default implementations of some of the interface methods
public void setSize(double width, double height) { w = width; h = height; }
public void setPosition(double x, double y) { this.x = x; this.y = y; }
public void translate (double dx, double dy) { x += dx; y += dy; }
}
超级会员免费看
订阅专栏 解锁全文
1392

被折叠的 条评论
为什么被折叠?



