Bird
0
0

Which of the following is the correct way to annotate a method for asynchronous execution in Spring Boot?

easy📝 Syntax Q3 of 15
Spring Boot - Async Processing

Which of the following is the correct way to annotate a method for asynchronous execution in Spring Boot?

public void sendEmail() { /* code */ }
Apublic @Async void sendEmail() { /* code */ }
B@Async() public void sendEmail { /* code */ }
C@Async public void sendEmail() { /* code */ }
Dpublic void sendEmail() @Async { /* code */ }
Step-by-Step Solution
Solution:
  1. Step 1: Understand annotation placement

    Annotations in Java are placed before the method signature without parentheses if no parameters are needed.
  2. Step 2: Validate correct syntax

    @Async public void sendEmail() is correct. @Async() public void sendEmail { /* code */ }, public @Async void sendEmail() { /* code */ } and D are invalid syntax.
  3. Final Answer:

    @Async public void sendEmail() { /* code */ } -> Option C
  4. Quick Check:

    Correct annotation syntax = @Async public void sendEmail() { /* code */ } [OK]
Quick Trick: Place @Async directly before method signature [OK]
Common Mistakes:
  • Putting @Async after method name
  • Using parentheses unnecessarily
  • Placing @Async inside method body

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes