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.


How can you access the outer class's reference from an inner class?

  1. Using Outer.this

  2. Directly by the outer class name

  3. It's not possible

  4. Using a special method getOuter()

The correct answer is: Using Outer.this

In Java, when an inner class is accessed from an outer class, it creates a special bond between the two. By using the keyword 'this' in the inner class, the special bond can be accessed in order to obtain the outer class's reference. Options B and C are incorrect as the outer class name cannot be used directly to access its reference and it is indeed possible to access the outer class's reference from an inner class. Option D is incorrect as there is no specific method called getOuter() for accessing the outer class's reference.