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 you create an object of an inner class without an instance of the outer class?

  1. Yes

  2. No

  3. Only if the inner class is static

  4. Only if the constructor is public

The correct answer is: Only if the inner class is static

An inner class is a class within another class. It can only be accessed through an instance of the outer class. This means that to create an object of an inner class, an instance of the outer class must first be created. Therefore, options A, B, and D are incorrect as they all require an instance of the outer class. The only option that is correct is C, which states that an object of an inner class can be created without an instance of the outer class if the inner class is declared as static. This means that the inner class is not tied to any specific instance of the outer class and can be accessed independently.