public class Test{
public static void main(String[] args){
Son son = new Son();
}
}
class Son{
Father father = new Father();
static{
System.out.println("Son static");
}
public Son(){
System.out.println("Son()");
}
}
class Father {
static{
System.out.println("Father static");
}
public Father(){
System.out.println("Father()");
}
}
输出结果:
Son static
Father static
Father()
Son()
public class Test{
public static void main(String[] args){
Son son = new Son();
}
}
class Father {
{
System.out.println("Father code block");
}
static{
System.out.println("Father static");
}
public Father(){
System.out.println("Father()");
}
}
class Son extends Father{
{
System.out.println("Son code block");
}
static{
System.out.println("Son static");
}
public Son(){
System.out.println("Son()");
}
}
输出结果:
Father static
Son static
Father code block
Father()
Son code block
Son()