我正在學習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