A. An interface declaration: Yes, the @Resource annotation can be applied to an interface because interfaces are considered types in Java. B. A local variable declaration: No, the @Resource annotation cannot be applied to local variables because they are not considered types. C. A class declaration: Yes, the @Resource annotation can be applied to a class because classes are considered types in Java. D. A method declaration: No, the @Resource annotation cannot be applied to methods because they are not considered types. E. A field declaration: No, the @Resource annotation cannot be applied to fields because they are not considered types.
A & C:
The @Target annotation is used to specify the kinds of program element to which an annotation type is applicable. In this case, @Target(TYPE) means that the @Resource annotation can be applied to any type declaration. In Java, a type declaration is any class, interface, enum, or annotation type declaration. Therefore, the @Resource annotation can be applied to an interface declaration (option A) and a class declaration (option C). The @Resource annotation cannot be applied to a local variable declaration (option B), a method declaration (option D), or a field declaration (option E) because these are not type declarations.
The @Resource annotation is used to identify a class, field, or method that upon initialization, the resource will be injected. For a class-based @Resource, the "resource is looked up by the application at runtime"
C,D,E
Resource annotation is used to declare a reference to a resource; @Resource can decorate a class, a field, or a method.
upvoted 3 times
...
Log in to ExamTopics
Sign in:
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.
Upvoting a comment with a selected answer will also increase the vote count towards that answer by one.
So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.
cathDev
3 months, 3 weeks agod7bb0b2
6 months, 1 week agod7bb0b2
7 months, 1 week agoduydn
8 months agoMabuzaT
9 months, 1 week agodilleman
9 months, 3 weeks ago[Removed]
10 months, 3 weeks agoStavok
12 months ago