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;
}
}
为什么编译不能通过?作者: 凊係柈泩 时间: 2012-12-19 10:29
public Demo(String s)
{
super();//隐式super;
i= 2;
}
子类方法中调用隐式super();会找父类中有没有空参的构造函数,父类中没有所以程序未通过编译,修改如下:
class Super
{
int i= 0;
/*
public Super(){