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()这句话才不会提示错误呢?令人
费解,请教各位帮我分析一下.
解决方案 »
- 关于jtextpane中输入文字的问题
- JFrame窗口打开另一个独立的JFrame窗口的问题
- 用java怎么能把汉字转成UNICODE码
- 关于进程的小问题
- 如何安装Eclipse,请教各位!
- 我编译java文件时为什末在Jcreate里好用,在dos下能生成类,却运行不了呢? 在别人机器上好用,在我的Jcreate上也好用
- JAVA算法研究书
- 高分求救:Java Mail收邮件时的中文问题
- 画了2周写了一个俄罗斯方块Applet(1300),欢迎到 go2play.126.com 下载和试玩,请多提宝贵意见.
- 生产者消费者和环形缓冲区代码,请大牛给指点下,扛不住鸟。。。
- 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来咯.