Java SE 11 Developer (1Z0-819) — Question 59
Which declaration of an annotation type is legal?
Answer options
- A. @interface Author { String name() default “”; String date(); }
- B. @interface Author extends Serializable { String name() default “”; String date(); }
- C. @interface Author { String name() default null; String date(); }
- D. @interface Author { String name(); String date; }
- E. @interface Author { String name(); String date default “”; }
Correct answer: A
Explanation
Option A is correct because it adheres to the rules of annotation declaration, allowing for a default value for the 'name' method while 'date' is required. Option B is incorrect as annotation types cannot extend other classes or interfaces. Option C is invalid because 'null' cannot be used as a default value. Options D and E are both wrong due to 'date' not being a method in D and the incorrect syntax in E.