|
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 fell{
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
我有三个问题:
1:在class Two里,为什么static One one_3=new One("one-3");前面有了个static后,就会先运行它(因为我在运行结果里看到他是先显示的) ? 不是声明为静态后,就不会分配空间给它了吗 ?
2:在结果里,为什么输出了Test main() start ...后,one-3就没再出现了 ?
3:static的优先级很高吗 ?static Two two_3=new Two("two-3");后,class One和class Two里面的内容都运行过了 ? 是否它的优先级很高,还是怎么回事 ?
麻烦大家帮我看看,, 谢谢 |
|