请教大家super代表什么?
照书上说super应该表示是被继承类的构造函数但java编程思想第十章中一个程序把我搞糊涂了:
class WithInner
{
class Inner
{
}
}
public class InheritInner extends WithInner.Inner
{
InheritInner(WithInner wi)
{ wi.super();}
public static void main(String args[])
{
WithInner wi = new WithInner();
InheritInner ii = new InheritInner(wi);
}
}
可以编译运行。wi.super表示的应该是WithInner这个类的构造函数
可我把程序改成下面这样:
class WithInner
{
public WithInner()
{
System.out.println("WithInner Constructor");
}
class Inner
{
public Inner(String a){ System.out.println("Inner Constructor."+a);}
}
}
public class InheritInner extends WithInner.Inner
{
// InheritInner(WithInner wi){ wi.super();}
public InheritInner(WithInner wi)
{
wi.super("aaaa");//假如是wi.super()则出错。表明wi.super("aaaa");代表是Inner的构造函数.
System.out.println("-----------------");
System.out.println("InheritInner()");
}
public static void main(String args[])
{
WithInner wi = new WithInner();
InheritInner ii = new InheritInner(wi);
}
}
也可以运行,运行结果:
WithInner Constructor
Inner Constructor.aaaa
-----------------
InheritInner()
这表示wi.super("aaaa")代表的是内部类Inner的构造函数。这怎么可能呢?
有没有高人告诉我wi.super()代表是WithInner的构造函数还是Inner类的构造函数还是别的什么?
[ 本帖最后由 Hallelujah 于 2009-11-4 16:48 编辑 ]