class One
{
public One(String str)
{
System.out.println(str);
}
}
class Two
{
One one_1 = new One("one-1");
One one_2 = new One("one-2");
static One one_3 = new One("one-3");
public Two(String str)
{
System.out.println(str);
}
}
public class Test
{
static Two two_3 = new Two("two-3");
public static void main(String[] args)
{
System.out.println("Test main() start...");
Two two_1 = new Two("two-1");
System.out.println("------------");
Two two_2 = new Two("two-2");
}
}
/****************************输出结果***********************************/
one-3
one-1
one-2
two-3
Test main() start...
one-1
one-2
two-1
------------
one-1
one-2
two-2
/****************************注释***********************************/
JAVA程序的执行顺序:静态块-->静态变量-->main()-->对象的成员变量-->构造函数
须要注意的是静态变量只会执行一次就会一直存在。