Mastering Java: The Ultimate Quiz for 'Thinking in Java'

Disable ads (and more) with a membership for a one time $2.99 payment

Dive into the depths of Java with our quiz based on "Thinking in Java, Fourth Edition" by Bruce Eckel. Test your knowledge, solidify concepts, and prepare for certification with challenging questions and insightful feedback.

Each practice test/flash card set has 50 randomly selected questions from a bank of over 500. You'll get a new set of questions each time!

Practice this question and more.


Can a private inner class be accessed outside of its enclosing class?

  1. Yes, using reflection

  2. No

  3. Yes, if a public method returns its reference

  4. Yes, by inheriting the outer class

The correct answer is: No

Private inner classes are not accessible outside of their enclosing class because they have restricted access modifiers. Option A is incorrect because although reflection can allow access to private members, it cannot bypass the access modifier set on the inner class. Option C is incorrect because a public method within the enclosing class would not be able to access the private inner class. Option D is incorrect because inheriting the outer class does not automatically grant access to the private inner class.