我正在学习 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 新手,对这些高级主题不太了解
谢谢