🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: static, final and Nested Classes: all 10 questions

Quiz: static, final and Nested Classes · Question 6 of 10

Why is a static nested class often preferred over an inner class?

Why is a static nested class often preferred over an inner class?

  1. A.It does not hold a hidden reference to an outer object, so it uses less memory and is simpler
  2. B.It runs faster because it is compiled twice
  3. C.Only static nested classes can have methods
  4. D.Inner classes cannot read private fields
Answer & explanation

Correct answer: It does not hold a hidden reference to an outer object, so it uses less memory and is simpler

An inner object keeps its outer object alive. If you do not need the outer object, static is the better choice.

Can you get the rest right without peeking?

Take the timed Quiz: static, final and Nested Classes quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →