黑马程序员技术交流社区
标题:
内部类调用问题
[打印本页]
作者:
chuanyueing
时间:
2013-3-8 10:01
标题:
内部类调用问题
public class TheOne {
public class TheInOne{
TheInOne(int n)
{
}
}
}
public class TheTwo extends TheOne.TheInOne{
TheTwo(TheOne to,int n){
to.super(n);
}
}
复制代码
请问to.super(n);这个语法怎么解释?
如果吧super理解为是TheOne父类执行构造函数来绑定对象显然不通啊。。。
作者:
张豪杰
时间:
2013-3-8 10:38
public class TheOne {
public class TheInOne{
TheInOne(int n){
System.out.println(n);
}
}
public static void main(String[] args){
TheTwo tt = new TheTwo(new TheOne(),1);
//TheOne.TheInOne tti = new TheOne().new TheInOne(123);
}
}
class TheTwo extends TheOne.TheInOne{//这里继承的不是TheOne,而是它的内部类!
TheTwo(TheOne to,int n){
to.super(n);//因为继承的是内部类,所以这里的super是指向TheInone;相当于new TheOne().new TheInOne(n)
}
}
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2