Exam 1z0-819 All QuestionsBrowse all questions from this exam
Question 133

Given this declaration:

@Target(TYPE)

@interface Resource {}

For which two kinds of declarations can the @Resource annotation be applied? (Choose two.)

    Correct Answer: A, C

    The @Target(TYPE) annotation restricts the @Resource annotation to be used on any program elements that are types. In Java, types include class declarations, interface declarations, enum declarations, and annotation type declarations. Thus, the @Resource annotation can be applied to an interface declaration and a class declaration. Local variable declarations, method declarations, and field declarations are not considered type declarations, so the @Resource annotation cannot be applied to them.

Discussion
dillemanOptions: AC

A and C. @Target(TYPE) can be applied to Interface, class or enum.

StavokOptions: CD

C,D,E Resource annotation is used to declare a reference to a resource; @Resource can decorate a class, a field, or a method.

duydnOptions: AC

A & C See: https://www.geeksforgeeks.org/java-target-annotations/

cathDevOptions: AC

Tested AC

d7bb0b2Options: AC

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.

d7bb0b2Options: AC

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.

MabuzaTOptions: CE

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"

[Removed]Options: AC

Straight from oracle.docs = Class, interface (including annotation type), or enum declaration