← Quiz: Nested and Anonymous Classes: all 10 questions
Quiz: Nested and Anonymous Classes · Question 6 of 10
Why is a static nested class usually preferred when the nested class does not use outer fields?
Why is a static nested class usually preferred when the nested class does not use outer fields?
- A.Static classes run faster
- B.Inner classes cannot have methods
- C.It avoids a hidden reference to the outer object, which costs memory and can keep the outer object alive
- D.Static nested classes can be public; inner classes cannot
Answer & explanation
Correct answer: It avoids a hidden reference to the outer object, which costs memory and can keep the outer object alive
An inner object always holds Outer.this, even if it never uses it.
Can you get the rest right without peeking?
Take the timed Quiz: Nested and Anonymous Classes quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →