当前所在位置:珠峰网资料 >> 计算机 >> 计算机等级考试 >> 正文
Java中执行顺序
发布时间:2010/8/6 10:20:13 来源:城市学习网 编辑:ziteng
  所以上面的例子打印顺序应该是这样的:
  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();//语句(*)
  }
  }
广告合作:400-664-0084 全国热线:400-664-0084
Copyright 2010 - 2017 www.my8848.com 珠峰网 粤ICP备15066211号
珠峰网 版权所有 All Rights Reserved