J.II · Java 25 practice question

Suppose inner class S is a member of class C due to inheritance, and C invokes S's superclass constructor. Can this itself (the zeroth lexically enclosing instance) be used as the immediately enclosing instance with respect to S?

Choose one answer
Check answer and explanation

Correct answer: No, the zeroth lexically enclosing instance of this is never used as the immediately enclosing instance with respect to S.

Explanation

Even when S is a member of C through inheritance, the zeroth lexically enclosing instance of this (this itself) is never used as the immediately enclosing instance of the new object with respect to S.

Common trap

Inherited membership makes it tempting to treat this as the enclosing instance, but the JLS explicitly requires the n'th lexically enclosing instance with n at least 1. Whether C is static or not does not allow this itself to serve as the immediately enclosing instance.

Source: JLS SE 25 §8.8.7.1. Constructor Invocations
Checked against the cited text on 2026-11-25.

Report an error in this question