Page 1 of 1

About Question com.enthuware.ets.scjp.v6.2.479 :

Posted: Sun Mar 18, 2018 4:29 pm
by TwistedLizard
What classes can a non-static nested class extend ?
(Provided that the class to be extended is visible and is not final.)

Given answer is
3: Any Class

Shouldn't option
2: 'Any top level class.'
also be correct?

It's a subset of option 3 and also therefore correct.

Re: About Question com.enthuware.ets.scjp.v6.2.479 :

Posted: Sun Mar 18, 2018 8:24 pm
by admin
No, "Any class" is the best option because of the reason you mentioned.

Re: About Question com.enthuware.ets.scjp.v6.2.479 :

Posted: Mon Mar 19, 2018 2:44 am
by TwistedLizard
ok, thanks.

I thought I remembered answers here where the the logic was that both answers should be included. Maybe that memory is mistaken.

I think that in the actual test, the number of required answers is given.

Re: About Question com.enthuware.ets.scjp.v6.2.479 :

Posted: Mon Mar 19, 2018 3:48 am
by admin
Yes, that depends on how many answers you have to select. If only one then the best answer wins :)

Re: About Question com.enthuware.ets.scjp.v6.2.479 :

Posted: Sat Apr 10, 2021 4:40 am
by marcioggs
Shouldn't the correct answer be "None of the above" since it can't extend a final class?

Code: Select all

public class Outer {

    final class FinalClass {

    }

    // Compiler error: Cannot inherit from final 'Outer.FinalClass'
    class NonStaticNested extends FinalClass {

    }
}

Re: About Question com.enthuware.ets.scjp.v6.2.479 :

Posted: Sat Apr 10, 2021 7:30 am
by admin
Yes, that's why the last line of the problem statement says: (Provided that the class to be extended is visible and is not final.)

Re: About Question com.enthuware.ets.scjp.v6.2.479 :

Posted: Sat Sep 17, 2022 12:53 pm
by sohamdatey22
Can a call extend itself? if not, then Any class cannot be the correct answer.
It will cause, cycle detected compilation error, thus.
Any class except itself, otherwise none of the above.

Re: About Question com.enthuware.ets.scjp.v6.2.479 :

Posted: Sun Sep 18, 2022 12:10 am
by admin
You are logically correct but the usage of extend itself is applicable to a class other than itself. A class cannot use extends keyword on itself, in any situation, right? So that part has nothing to do with nested classes. In other words, "extends" implicitly implies a class other than itself. The problem statement therefore is clearly trying to explore if there are more restrictions on a nested class.