love fish大鹏一曰同风起,扶摇直上九万里

常用链接

统计

积分与排名

friends

link

最新评论

类初始化与对象初始化 (转)

what's the output?
/**
 * @author 031202
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
class Parent {
 
 class InnerClass {
  public InnerClass() {
   System.out.println("Construct parent's inner class");
  }
 }
 
 static class StaticInner {
  public StaticInner() {
   System.out.println("Construct parent's StaticInner class");
  }
 }
 
 private InnerClass i = new InnerClass();
 
 private static StaticInner s = new StaticInner();
 
 public Parent() {
  System.out.println("Construct Parent");
 }

}

public class Child extends Parent {
 class InnerClass {
  public InnerClass() {
   System.out.println("Construct child's inner class");
  }
 }
 
 static class StaticInner {
  public StaticInner() {
   System.out.println("Construct child's StaticInner class");
  }
 }
 
 private static StaticInner s = new StaticInner();
 
 private InnerClass i = new InnerClass();
 
 public Child() {
  System.out.println("Construct Child");
 }
 
 public static void main(String[] args) {
  new Child();
 }
}
answer:
Construct parent's StaticInner class
Construct child's StaticInner class
Construct parent's inner class
Construct Parent
Construct child's inner class
Construct Child

Do you really understnand  the class initialization?


posted on 2007-03-16 17:07 liaojiyong 阅读(303) 评论(0)  编辑  收藏 所属分类: Java


只有注册用户登录后才能发表评论。


网站导航: