【发布时间】:2016-06-03 02:44:20
【问题描述】:
我发现了这个问题,但我不明白为什么在第一种情况下会继承构造函数。 据我所知,构造函数不是继承的。我错过了一些非常重要的东西吗?
class Bird {
{ System.out.print("b1 ");}
public Bird() {System.out.print("b2 ");}
class Raptor extends Bird
{
static {System.out.print("r1 ");}
public Raptor() {System.out.print("r2 ");}
{
{ System.out.print("r3 ");}
static {System.out.print("r4 ");}
}
class Hawk extends Raptor
{
public static void main(String[] args)
{
System.out.print("pre ");
new Hawk();
System.out.println("hawk ");
}
}
上面的答案是:
r1 r4 pre b1 b2 r3 r2 鹰
【问题讨论】:
-
清理您的格式并更具体地说明您要演示的内容。
-
这看起来合乎逻辑。问题是什么?你有什么不明白的?
-
我问输出是怎么来的
标签: java