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

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

Want to excel in Java? Test your knowledge with our ultimate quiz based on 'Thinking in Java'. Engage with multiple-choice questions and in-depth explanations. Boost your understanding and prepare for your exam with confidence.

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 do you invoke a protected method from a subclass?

  1. Directly, if in the same package

  2. Using super keyword

  3. By creating an object of the superclass

  4. It is not accessible from a subclass

The correct answer is: Directly, if in the same package

Directly invoking a protected method from a subclass is possible if they are in the same package. If the subclass is not in the same package as the superclass, then the method cannot be directly invoked. B and C are incorrect because they do not refer to the protection level of the method or the package. D is incorrect because a protected method can be accessed from a subclass, in this case, as long as they are in the same package.