1Z0-819 · Question #141
Which of the following are true about annotations?
The correct answer is C. Annotations can be applied to classes, methods, expressions, and annotations D. When using a marker annotation, parentheses are optional. Options C and D are correct because Java annotations can target a wide range of program elements - classes, interfaces, methods, fields, parameters, local variables, constructors, and even other annotations (via meta-annotations like @Target). Additionally, a marker annotation…
Question
Options
- AAnnotation names are not case sensitive.
- BAnnotations enable compile-time error.
- CAnnotations can be applied to classes, methods, expressions, and annotations
- DWhen using a marker annotation, parentheses are optional
- ENone of these
- FAll of these
How the community answered
(47 responses)- A2% (1)
- B2% (1)
- C85% (40)
- E6% (3)
- F4% (2)
Explanation
Options C and D are correct because Java annotations can target a wide range of program elements - classes, interfaces, methods, fields, parameters, local variables, constructors, and even other annotations (via meta-annotations like @Target). Additionally, a marker annotation (one with no elements, such as @Override) allows the parentheses to be omitted, so @Override and @Override() are both valid syntax.
Why the distractors fail:
- A is false - Java is entirely case-sensitive;
@Overrideand@overrideare distinct identifiers. - B is false - annotations themselves are metadata; they don't inherently "enable" compile-time errors. It's the compiler or annotation processor that may act on them to produce errors (e.g.,
@Overridetriggers an error only if no supertype method matches). - E/F are ruled out since A and B are incorrect.
Memory tip: Think of annotations as sticky labels - you can slap them on almost anything in your code (C), and if the label has no fields to fill in, you don't need to open the parentheses at all (D). The two falsehoods are about Java basics: Java is always case-sensitive (A), and annotations are passive metadata, not active error generators (B).
Topics
Community Discussion
No community discussion yet for this question.