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.


What is a drawback of using reflection in Java?

  1. It can only call public methods

  2. It is slower than direct method calls

  3. It cannot access private fields

  4. It is not supported in modern Java versions

The correct answer is: It is slower than direct method calls

Reflection allows for the inspection and manipulation of code at runtime, which can be useful in some cases. However, it comes with a performance cost as it involves additional layers of abstraction and dynamic method lookups. Therefore, option B is correct as it states that a drawback of using reflection in Java is that it is slower than direct method calls. While option A, C, and D are incorrect because they do not identify a drawback of using reflection in Java. Option A is incorrect because reflection can actually access and call both public and private methods. Option C is incorrect because reflection does have the ability to access and modify private fields, although it requires additional permissions. Finally, option D is also incorrect as reflection is still supported in modern Java versions, although there are other alternatives that may be preferred in certain situations.