1Z0-819 · Question #13
Which is the correct order of possible statements in the structure of a Java class file?
The correct answer is B. package, import, class. Option B (package, import, class) is correct because Java enforces a strict syntactic order: the package declaration must appear first (if present) to tell the compiler which package this file belongs to, followed by any import statements that bring in external types, and…
Question
Options
- Aclass, package, import
- Bpackage, import, class
- Cimport, package, class
- Dpackage, class, import
- Eimport, class, package
How the community answered
(69 responses)- A1% (1)
- B83% (57)
- C4% (3)
- D1% (1)
- E10% (7)
Explanation
Option B (package, import, class) is correct because Java enforces a strict syntactic order: the package declaration must appear first (if present) to tell the compiler which package this file belongs to, followed by any import statements that bring in external types, and finally the class declaration where your actual code lives.
Why the distractors fail:
- A (class, package, import) -
classcannot precedepackage; the compiler expectspackageat the very top. - C (import, package, class) -
importcannot come beforepackage; imports depend on the package context already being established. - D (package, class, import) - imports must be resolved before the class body is parsed, so
importcannot followclass. - E (import, class, package) - both
importbeforepackageandclassbeforepackageare wrong for the reasons above.
Memory tip: Think "Please In Class" - Package, Import, Class. The most general declaration (which package am I in?) comes first, then what you need from outside (imports), then the specific code (class).
Topics
Community Discussion
No community discussion yet for this question.