1Z0-900 · Question #13
Given the code fragment: And Which two steps, when performed independently, enable the index.xhtml page to print the following text: The Id is 12345? (Choose two.)
Options A and C are the two correct answers. CDI (Contexts and Dependency Injection) supports field injection and method (setter) injection as two independent ways to inject a managed bean. Option C (@Inject private Account acc;) correctly uses field injection by placing…
Question
Given the code fragment:
And Which two steps, when performed independently, enable the index.xhtml page to print the following text: The Id is 12345? (Choose two.)
Exhibit
Options
- AReplace line 2 with: @Inject public void setAcc(Account acc)
- BReplace line 3 with: @Inject public Account getAcc()
- CReplace line 1 with: @Inject private Account acc;
- DReplace line 3 with: public @Inject Account getAcc()
- EReplace line 1 with: private @Inject Account acc;
- FReplace line 2 with: public void setAcc(@Inject Account acc)
Explanation
Options A and C are the two correct answers.
CDI (Contexts and Dependency Injection) supports field injection and method (setter) injection as two independent ways to inject a managed bean. Option C (@Inject private Account acc;) correctly uses field injection by placing @Inject directly before the field declaration - the standard, spec-compliant placement. Option A (@Inject public void setAcc(Account acc)) correctly uses setter/method injection by annotating the method itself, which signals CDI to call that method and supply the dependency.
Why the others fail:
- B and D place
@Injecton the getter - CDI does not inject via getters; getters only read values, they don't receive dependencies. - E places
@Injectafter the access modifier (private @Inject), which is non-standard; CDI requires the annotation to precede access modifiers for field injection. - F places
@Injecton the parameter of a regular setter, not the method itself - parameter-level injection is only valid for constructors, not arbitrary methods.
Memory tip: Think of @Inject as marking the entry point where CDI delivers the object - the field or the method door must be marked, not the parameter slot inside or the exit (getter). If CDI can't see @Inject at the door, it won't knock.
Topics
Community Discussion
No community discussion yet for this question.
