首页 > 编程语言 > 详细

Java类的成员函数调用顺序

时间:2014-12-23 10:15:13      阅读:307      评论:0      收藏:0      [点我收藏+]
 1 class A
 2 {
 3  public A()
 4  {
 5   System.out.println("----------A 构造-------------");
 6  }
 7  static 
 8  {
 9   System.out.println("----------A 静态块-------------");
10  }
11  {
12   System.out.println("----------A 语句块-------------");
13  }
14 }
15 
16 class B extends A
17 {
18  public B()
19  {
20   System.out.println("----------B 构造-------------");
21  }
22  static 
23  {
24   System.out.println("----------B 静态块-------------");
25  }
26  {
27   System.out.println("----------B 语句块-------------");
28  }
29 }
30 
31 public class initSequence 
32 {
33  public static void main(String[] args)
34  {
35   System.out.println("First time new: ");
36   B b=new B();
37   System.out.println("Second time new: ");
38   B b1=new B();
39  }
40 }

输出:

First time new:
----------A 静态块-------------
----------B 静态块-------------
----------A 语句块-------------
----------A 构造-------------
----------B 语句块-------------
----------B 构造-------------
Second time new:
----------A 语句块-------------
----------A 构造-------------
----------B 语句块-------------
----------B 构造-------------

 

Java类的成员函数调用顺序

原文:http://www.cnblogs.com/dracohan/p/4179475.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!