我正在学习Java中的内部和外部类。我知道内部和外部类是什么以及为什么使用它们。我在这个话题上遇到了以下问题,但找不到答案。如何定义继承内部类的子类的构造函数?
假设下面的代码给出:
class outer{
class inner{
}
}
class SubClass extends outer.inner{
}
问:应该如何最小的子类构造函数中定义?为什么?
Option 1-
Subclass() {
//reason: bacause the default constructor must always be provided
}
Option 2-
Subclass (Outer outer) {
//reason : because creating an instance of **Subclass** requires an instance
//of outer, which the **Subclass** instance will be bound to
}
Option 3-
Subclass (Outer outer) {
outer.super();
//reason : because creating an instance of **Subclass** requires an explicit
//call to the **Outer's** constructor, in order to have an enclosing instance
//of **Outer** in scope.
}
Option 4-
Subclass (Outer.inner inner) {
//reason : bacause an instance of **inner** is necessary so that there is a
//source to copy the derived properties from
}
PS。这是一个多选题。只有1回答预计
我是新来的Java,不知道太多关于这些高级的主题
感谢
相信没有以上的,并认为这是对一个[接收机参数的情况下 - JLS# 8.4.1](http://docs.oracle.com/javase/specs/jls/se8/html/jls-8.html#jls-8.4.1)。 – EJP