Java Interface Annotations with Default Values
Short answer
ABC @Resource(“Customer2”) omits the name for the single element, @Resource(value=“Customer2”) specifies it explicitly, and @Resource uses the default.
Question
Key Takeaways
Tests knowledge of Java annotation element binding rules, specifically the omission of the 'value' parameter name when it is the sole element or has a default.
Determines valid syntax for applying an interface annotation with a default attribute value. Establishes that explicit naming is optional for single-value attributes and defaults can be omitted.
Common mistake: Selecting Option D using 'val=' instead of 'value=', which violates the specific attribute name defined in the @interface declaration.
Expert Analysis
Why the Answer Is Correct
The @interface defines a single element named 'value' with a default string. In Java, if an annotation has only one element named 'value', the element name can be omitted entirely (Option A). If there are multiple elements or to be explicit, 'value=' must be used (Option B). Since a default is provided, the annotation can also be applied without specifying any values at all (Option C). Options A, B, and C are syntactically correct.
Why the Other Options Are Wrong
Option D uses 'val=' which is not the defined element name ('value'). Option E uses array syntax {} for a String type, which is invalid.
Community Comment Notes
Multiple users correctly identified that A, B, and C are all valid, noting that the default allows omission (C) and the single-element rule allows omitting the name (A).
Exam Strategy
Always check the exact element names defined in the annotation interface. Remember that 'value' is special: it can be omitted if it's the only element.
Frequently Asked Questions
Can I omit the 'value' name?
Is 'val=' allowed?
Community Votes
100% of anonymous learners picked answer AC. Votes are pick records left by other test-takers — they are not the verified answer.
Discussion 3 contributions
Compiled from public community threads and reader submissions, lightly edited for clarity. Handles and vote tallies are shown as recorded, and comments reflect the views of individual contributors.
From public community threads 3
-
d7bb0b2 👍 2No options can be selected, 3 are valid: A : cause only one elemente called value B : cause explicit value C: cause has default value then can used withot pass anything
-
ASPushkin 👍 2answer: ABC A) correct if there is just one element named value, then name can be omitted. B) correct C) correct default values can be omitted D) E) invalid syntax
-
d7bb0b2 👍 1ABC if anotation haved a other value and is not set by default for value an other field then is requierd especified the name of two elements
Reader comments & corrections
No reader corrections yet — spotted an error or have a note? Share it below.