nerdexam
Oracle

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…

Annotations

Question

Which of the following are true about annotations?

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)
  • A
    2% (1)
  • B
    2% (1)
  • C
    85% (40)
  • E
    6% (3)
  • F
    4% (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; @Override and @override are 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., @Override triggers 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

#annotations#marker annotations#annotation targets#annotation syntax

Community Discussion

No community discussion yet for this question.

Full 1Z0-819 Practice