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's true about package and import declarations in a Java file?

  1. Both can be placed anywhere in the file

  2. Both must be the first statements in the file

  3. The package declaration must be first, followed by imports

  4. Imports must be first, followed by the package declaration

The correct answer is: The package declaration must be first, followed by imports

In a Java file, the package declaration must be the first line of code, followed by any import declarations. This is because the package declaration determines which package the file belongs to, while the import declarations specify which external packages or classes are being used within the current file. Incorrect options include A, as both declarations must be placed at the top of the file, and D, as the package declaration must always come before any import declarations. Option B is also incorrect because while the package declaration must be first, there can be other lines of code before any import declarations. Option C is the only correct answer.