问下面程序输出结果:
public class Test3{
public static void main(String[] args){
FlyMen f = new FlyMen();
}
}
class Bird{
static int wingsNumber = 2;
static {
System.out.println ("I am Bird");
}
public Bird(){
System.out.println ("Bird constructor");
}
}
class FlyMen extends Bird{
static{
System.out.println ("I am fly Men");
}
public FlyMen(){
System.out.println ("fly constructor");
}
}
运行结果:
I am Bird
I am fly Men
Bird constructor
fly constructor
主要考察的是static和游离块的用法,有些变态,如果将Bird类中游离块前的static去掉,则输出结果为:
I am fly Men
I am Bird
Bird constructor
fly constructor