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.


Can 'return' statements be used in case statements without a default case?

  1. Yes, without any complaints

  2. Yes, but with compiler complaints

  3. No, it's not allowed

  4. It depends on the enum

The correct answer is: Yes, but with compiler complaints

The return statement can be used in case statements, even without a default case, but the compiler will issue a warning if the case statements do not cover all possible values. This is because without a default case, there is a possibility that not all values will be accounted for and the program may not function correctly. Therefore, it is considered good practice to have a default case in case statements. Answer B is correct because although the return statement can be used, the compiler will issue a warning. Options A, C, and D do not accurately describe the use of return statements in case statements. Option A is incorrect because although the return statement can be used, the compiler may still issue a warning. Option C is incorrect because return statements can be used in case statements. Option D is incorrect because whether or not the return statement can be used depends on the situation and not just the enum.