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 inner classes be declared private or protected?

  1. Yes

  2. No

  3. Only private

  4. Only protected

The correct answer is: Yes

Inner classes can be declared with any access modifier, including private and protected. However, it is common practice to declare inner classes as private so that they cannot be accessed or instantiated by other classes. Protected inner classes can be accessed by subclasses, but it is not commonly used. Therefore, options B, C, and D are incorrect as they imply that inner classes cannot have certain access modifiers. The correct answer is option A, as it acknowledges that inner classes can be declared with any access modifier.