Bird
0
0

Given the following advice:

medium📝 component behavior Q4 of 15
Spring Boot - Aspect-Oriented Programming
Given the following advice:
@AfterReturning(pointcut = "execution(* service.*.getData(..))", returning = "result")
public void logResult(Object result) {
    System.out.println("Result: " + result);
}

What will be printed if getData() returns "Hello"?
AResult: Hello
BResult: null
CNo output printed
DCompilation error
Step-by-Step Solution
Solution:
  1. Step 1: Understand advice execution

    @AfterReturning runs only if getData() returns successfully.
  2. Step 2: Output behavior

    The advice prints the returned value prefixed by "Result: ". Since return is "Hello", it prints "Result: Hello".
  3. Final Answer:

    Result: Hello -> Option A
  4. Quick Check:

    Return value passed to advice and printed [OK]
Quick Trick: Prints returned value only on successful return [OK]
Common Mistakes:
  • Expecting output on exceptions
  • Thinking advice runs before method
  • Assuming null is printed if return is non-null

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes