代码如下:
class Super
{
int i=0;
public Super(String s)
{
i=1;
}
}
class Demo extends Super
{
public Demo (String s)
{
i=2;
}
public static void main(String[] args)
{
Demo d = new Demo("yes");
System.out.println(d.i);
}
}
class Super
{
int i=0;
public Super(String s)
{
i=1;
}
}
class Demo extends Super
{
public Demo (String s)
{
super(s);//应该调用父类的构造函数给子类初始化
// i=2;
}
public static void main(String[] args)
{
Demo d = new Demo("yes");
System.out.println(d.i);
}
}