设为首页 加入收藏

TOP

Java中执行顺序
2014-11-13 23:15:04 来源: 作者: 【 】 浏览:22
Tags:Java 执行 顺序

  所以上面的例子打印顺序应该是这样的:


  parent static block 父类Static


  child static block 子类static


  parent block 父类缺省{}


  parent constructor 父类构造函数


  child block子类缺省{}


  child constructor子类构造函数


  class Parent{


  static String name = "hello";


  static {


  System.out.println("parent static block");


  }


  {


  System.out.println("parent block");


  }


  public Parent(){


  System.out.println("parent constructor");


  }


  }


  class Child extends Parent{


  static String childName = "hello";


  static {


  System.out.println("child static block");


  }


  {


  System.out.println("child block");


  }


  public Child(){


  System.out.println("child constructor");


  }


  }


  public class StaticIniBlockOrderTest {


  public static void main(String[] args) {


  new Child();//语句(*)


  }


  }


  编辑特别推荐:


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇关于计算Java程序运行时间 下一篇JavaIO读取文件中文乱码问题

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: