初学java 求教
抽象类不可以实例化 可是我在许多源码中东看到有这种情况啊
比如说最常见的有
Graphics g=[Component].getGraphics()
这里getGraphics()函数返回的是Graphics的具体子类吗?
函数具体定义是:
public Graphics getGraphics() {
if (peer instanceof LightweightPeer) {
// This is for a lightweight component, need to
// translate coordinate spaces and clip relative
// to the parent.
if (parent == null) return null;
Graphics g = parent.getGraphics();
if (g == null) return null;
if (g instanceof ConstrainableGraphics) {
((ConstrainableGraphics) g).constrain(x, y, width, height);
} else {
g.translate(x,y);
g.setClip(0, 0, width, height);
}
g.setFont(getFont());
return g;
} else {
ComponentPeer peer = this.peer;
return (peer != null) ? peer.getGraphics() : null;
}
}
还是看不明白
哪为大哥给小弟讲讲啊。点拨一下就好 呵呵 谢了