javaクラスのロード順序
1813 ワード
csdnで文章を見ました.原文の住所.http://bbs.csdn.net/topics/390973527.
javaコード:
javaコード:
public class StaticTest {
public static int k=0;
public static StaticTest s1=new StaticTest("s1");
public static StaticTest s2=new StaticTest("s2");
public static int i=print("i");
public static int n=99;
public int j=print("j");
{
print(" ");
}
static
{
print(" ");
}
public static int print(String s)
{
System.out.println(++k+":"+s+"\ti="+i+"\tn="+n);
++n;
return ++i;
}
public StaticTest(String s)
{
System.out.println(++k+":"+s+"\ti="+i+"\tn="+n);
++i;
++n;
}
public static void main(String[] args) {
new StaticTest("init");
}
}
そして結果は1:j i=0 n=0
2: i=1 n=1
3:s1 i=2 n=2
4:j i=3 n=3
5: i=4 n=4
6:s2 i=5 n=5
7:i i=6 n=6
8: i=7 n=99
9:j i=8 n=100
10: i=9 n=101
11:init i=10 n=102
初一は少しぼんやりしていることを見て、とても少なくこれに接触して、自分でそのまま取って、debugは流れをおります.写真が表示されるかどうかは分かりませんが、自分が見た結果はこうなります.まとめは以下の通りです