1Z0-803 · Question #191
Which two items can legally be contained within a java class declaration?
The correct answer is B. A field declaration D. A method declaration. This question assesses knowledge of the fundamental components that can legally reside within a Java class declaration.
Question
Which two items can legally be contained within a java class declaration?
Options
- AAn import statement
- BA field declaration
- CA package declaration
- DA method declaration
How the community answered
(23 responses)- A4% (1)
- B91% (21)
- C4% (1)
Why each option
This question assesses knowledge of the fundamental components that can legally reside within a Java class declaration.
Import statements must appear at the top of a Java source file, after an optional package declaration and before any class, interface, or enum declarations.
Field declarations, which define the member variables of a class, are legally contained within the curly braces of a class declaration. They represent the state of an object.
A package declaration must be the very first statement in a Java source file, preceding any import statements and all type declarations.
Method declarations, which define the behaviors or functions of a class, are legally contained within the curly braces of a class declaration. They represent actions an object can perform.
Concept tested: Java class structure components
Source: https://docs.oracle.com/javase/specs/jls/se11/html/jls-8.html#jls-8.1.6
Topics
Community Discussion
No community discussion yet for this question.