class A
{
class B
{ }
}
class C extends A.B
{
C(A a)
{
a.super();
}
public static void main(String args[])
{
A a=new A();
C c=new C(a);
}
}
上面的程序是继承内部类的一个示例,看了好多书,都是这么写的,但都没有说明原因.
虽然说如果C类想继承内部类B必有先有A类的实例对象才可以,这一点我能够理解,但是
为什么还要在C类中的构造函数再一次的调用a.super()这句话才不会提示错误呢?令人
费解,请教各位帮我分析一下.
{
class B
{ }
}
class C extends A.B
{
C(A a)
{
a.super();
}
public static void main(String args[])
{
A a=new A();
C c=new C(a);
}
}
上面的程序是继承内部类的一个示例,看了好多书,都是这么写的,但都没有说明原因.
虽然说如果C类想继承内部类B必有先有A类的实例对象才可以,这一点我能够理解,但是
为什么还要在C类中的构造函数再一次的调用a.super()这句话才不会提示错误呢?令人
费解,请教各位帮我分析一下.
解决方案 »
- 计算圆周率
- 用DefaultMutableTreeNode 构造的所有节点的一棵JTree,如何初始化展开
- core java&thinging in java!!!
- 实在看不太懂,请各位大侠解释下
- 500大分!异构系统的事务处理
- 老子毕业前四个月到深圳,cjol上投了10000多份简历,平均每天投300多份,我容易吗我
- 请教各位老师一个取配置文件test.property的值的问题。。。
- oracle取出汉字成?号
- 最简单的一APPLET,不用JRE的plug-in,为何不能运行,该如何处理?郁闷之极。。。
- 初学者提问:JDK如何配置?我急需要快速上手!
- session详解
- 请教:在jdk的核心库rt.jar中能否扩展新的类?
enclosing class object, things are slightly complicated when you inherit
from an inner class. The problem is that the “secret” reference to the
enclosing class object must be initialized, and yet in the derived class
there’s no longer a default object to attach to. The answer is to use a
syntax provided to make the association explicit: //: c08:InheritInner.java
// Inheriting an inner class.
class WithInner {
class Inner {}
}
public class InheritInner extends WithInner.Inner {
//! InheritInner() {} // Won't compile
InheritInner(WithInner wi) {
wi.super();
}
public static void main(String[] args) {
WithInner wi = new WithInner();
InheritInner ii = new InheritInner(wi);
}
} ///:~
You can see that InheritInner is extending only the inner class, not the
outer one. But when it comes time to create a constructor, the default one
is no good and you can’t just pass a reference to an enclosing object. In
addition, you must use the syntax FeedbackenclosingClassReference.super();inside the constructor. This provides the necessary reference and the
program will then compile.其实这段我自己都还没看到,我正好看到这章,看了下目录有讲这个的...就copy来咯.