抽象类不可以实例化  可是我在许多源码中东看到有这种情况啊
比如说最常见的有
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;
        }
  }还是看不明白
哪为大哥给小弟讲讲啊。点拨一下就好  呵呵  谢了

解决方案 »

  1.   

    可是getGraphics()函数中 我看不出返回的是哪个子类啊
      

  2.   

    Graphics g = parent.getGraphics();再往getGraphics()里面找
      

  3.   

    接口
    public interface MyIn {
    void MySpring(String name);}子类
    public class MySpringDo implements MyIn {
    public MySpringDo() {
    } public void MySpring(String name) {
    // TODO Auto-generated method stub
    System.out.println("MySpring---good work");
    System.out.println("void"+name);
    }}
    测试类
    public class TestMySpring { public static void main(String[] args) {
        MyIn testMySpring = new MySpringDo();///可以事例化他的子类呵呵    testMySpring.MySpring;
    }
    }
      

  4.   

    这是个递归过程
    具体操作应该在
    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;
            }
    里吧
    就是我找不到啊。
    Graphics
    好像只有两个子类  究竟是哪个啊?
      

  5.   

    是在这里:
    if (g instanceof ConstrainableGraphics) {
                    ((ConstrainableGraphics) g).constrain(x, y, width, height);
                } else {
                    g.translate(x,y);
                    g.setClip(0, 0, width, height);
                }
    ConstrainableGraphics 是个抽象接口
      

  6.   

    我就是不知道 Graphics 类 是实例化的那个子类  我想找到它研究一下