Bird
0
0

Which of the following is the correct way to declare a Spring bean using the @Component annotation?

easy📝 Syntax Q3 of 15
Spring Boot - Spring Annotations
Which of the following is the correct way to declare a Spring bean using the @Component annotation?
Apublic @Component class MyBean {}
Bpublic class MyBean @Component {}
C@Component public MyBean {}
D@Component public class MyBean {}
Step-by-Step Solution
Solution:
  1. Step 1: Recall correct annotation placement

    Annotations like @Component must be placed immediately before the class declaration.
  2. Step 2: Check syntax correctness

    @Component public class MyBean {} correctly places @Component above the class with proper syntax.
  3. Final Answer:

    @Component\npublic class MyBean {} -> Option D
  4. Quick Check:

    @Component before class = correct syntax [OK]
Quick Trick: Place @Component directly above the class declaration [OK]
Common Mistakes:
  • Placing annotation inside class
  • Incorrect annotation placement
  • Missing public keyword

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes