河南成教 / 河南理工大学
16[分析题]
class Ex0707Super
{
public Ex0707Super(String name)
{
System.out.println("superclass constructor" name);
}
}
class Ex0707Sub extends Ex0707Super
{
public Ex0707Sub(String name)
{
System.out.println("subclass constructor" name);
}
public Ex0707Sub()
{
System.out.println("subclass constructor no name");
super("no name");
}
}
public class Ex0707Demo
{
Ex0707Super superObj=new Ex0707Super("zhangsan");
Ex0707Sub subObj = new Ex0707Sub("lisi");
Ex0707Super superRef=subObj;
Ex0707Sub subRef=superObj;
}
上述程序存在3个错误,请指出来,并写出修改方案。
16[分析题]
class Ex0707Super
{
public Ex0707Super(String name)
{
System.out.println("superclass constructor" name);
}
}
class Ex0707Sub extends Ex0707Super
{
public Ex0707Sub(String name)
{
System.out.println("subclass constructor" name);
}
public Ex0707Sub()
{
System.out.println("subclass constructor no name");
super("no name");
}
}
public class Ex0707Demo
{
Ex0707Super superObj=new Ex0707Super("zhangsan");
Ex0707Sub subObj = new Ex0707Sub("lisi");
Ex0707Super superRef=subObj;
Ex0707Sub subRef=superObj;
}
上述程序存在3个错误,请指出来,并写出修改方案。
参考答案: