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

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

Master your knowledge of Java programming with our immersive quiz based on 'Thinking in Java'. Test your skills with detailed questions and receive hints and explanations to enhance your learning. Get ready to ace your Java exam!

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.