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 create a class object if its constructor is private?

  1. By inheriting the class

  2. By creating an object in a subclass

  3. By calling a public static method of the class meant for object creation

  4. You cannot create an object if the constructor is private

The correct answer is: By calling a public static method of the class meant for object creation

Creating a class object requires calling the constructor of the class. However, if the constructor is set to private, it cannot be called outside of the class. Therefore, options A and B are incorrect as they involve inheriting or subclassing the class, both of which still require calling the constructor. Option D is also incorrect as it provides a general statement without explaining why the constructor being private is significant. Option C is the correct answer as it suggests using a public static method of the class specifically designed for object creation, bypassing the private constructor restriction.