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.


Which access level prevents a class member from being accessed by any class outside its own package, except for subclasses?

  1. Private

  2. Protected

  3. Public

  4. Package access

The correct answer is: Protected

In Java, there are four different access levels public, protected, default (package access), and private. Out of these four, only the protected access level allows a class member to be accessed by a subclass outside of its package. The private access level would restrict access to only within the same class, the public access level would allow access by any class, and the default access level would only restrict access within the same package. Therefore, the protected access level is the correct choice as it meets the criteria set in the question while also providing context on why the other options are incorrect.