Java Interface Annotations with Default Values
Given the declaration: @inteface Resource { String value() default “Customer1”; } Examine this code fragment: / Loc1 / class ProcessOrders { ... } Which two annotations may be applied at Loc1 in the code fragment? (Choose two.)
Community Votes
100% of anonymous learners picked answer AC. Votes are pick records left by other test-takers — they are not the verified answer.
Community Insight
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.
Selecting Option D using 'val=' instead of 'value=', which violates the specific attribute name defined in the @interface declaration.
Community Discussion (3 comments)
Comments & Corrections
No comments yet — spotted an error or have a note? Share it below.
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?
Yes, if it is the only element in the annotation.
Is 'val=' allowed?
No, you must use the exact name 'value' as defined in the interface.