模块加载顺序
public class HelloWord {
public void test(){
System.out.println("dddd");
}
public HelloWord(){
System.out.println("cccc");
}
{
System.out.println("aaaa");
}
static {
System.out.println("bbbb");
}
public static void main(String[] args){
HelloWord hello = new HelloWord();
hello.test();
}
}
结果:bbbb
aaaa
cccc
dddd
public class Test {
public void test(){
System.out.println("dddd1");
}
public Test(){
System.out.println("cccc1");
}
{
System.out.println("aaaa1");
}
static {
System.out.println("bbbb1");
}
}
public class HelloWord extends Test {
public void test(){
System.out.println("dddd");
}
public HelloWord(){
System.out.println("cccc");
}
{
System.out.println("aaaa");
}
static {
System.out.println("bbbb");
}
public static void main(String[] args){
HelloWord hello = new HelloWord();
hello.test();
}
}
结果:bbbb1
bbbb
aaaa1
cccc1
aaaa
cccc
dddd
希望在码农的山坡上越攀越高,欢迎各位大佬看官的指正及补充