Skip to Content

Oracle 1z0-819: Applying @Resource Annotation

Learn which kinds of declarations the @Resource annotation can be applied to in the Oracle Java SE 11 Developer 1z0-819 certification exam. Understand the correct answers and explanations to ace this exam question.

Table of Contents

Question

Given this declaration:

@Target(TYPE)
@interface Resource {}

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

A. An interface declaration
B. A local variable declaration
C. A class declaration
D. A method declaration
E. A field declaration

Answer

C. A class declaration
E. A field declaration

Explanation

The @Resource annotation is used in Java for resource injection, typically for dependency injection in Java EE applications. According to the given declaration, the @Target annotation specifies that the @Resource annotation can only be applied to TYPE declarations.

In Java, TYPE includes class and interface declarations, as well as enum declarations and annotation type declarations. Therefore, the @Resource annotation can be applied to class declarations and interface declarations.

However, it cannot be applied to local variable declarations (option B), method declarations (option D), or any other kind of declaration besides TYPE.

By selecting options C and E, we correctly identify that the @Resource annotation can be applied to class declarations and field declarations, which are both considered TYPE declarations in Java.

Oracle Java SE 11 Developer 1z0-819 certification exam practice question and answer (Q&A) dump with detail explanation and reference available free, helpful to pass the Oracle Java SE 11 Developer 1z0-819 exam and earn Oracle Java SE 11 Developer 1z0-819 certification.