Java Interface Annotations with Default Values

Annotations
Answer Correct answer: A, B, C — @Resource(“Customer2”) omits the name for the single element, @Resource(value=“Customer2”) specifies it explicitly, and @Resource uses the default.

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.)

  1. @Resource(“Customer2”) Correct Answer
  2. @Resource(value=“Customer2”) Correct Answer
  3. @Resource Correct Answer
  4. @Resource(val=“Customer2”)
  5. @Resource({“Customer2”})

Community Votes

AC
100%

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)

d7bb0b2 👍 1 Selected: AC
ABC 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
ASPushkin 👍 2
answer: 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 👍 2
No 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

Comments & Corrections

No comments yet — spotted an error or have a note? Share it below.

Log in to comment, report an error, or add a note about this question.

Submitted for moderation before publishing. Keep it helpful and respectful.

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.

More 1Z0-819 FAQ →

Related Analysis

← Back to 1Z0-819 Study Guide