Bird
0
0

Given this @Around advice snippet, what will be the output if the target method returns "Hello"?

medium📝 component behavior Q4 of 15
Spring Boot - Aspect-Oriented Programming
Given this @Around advice snippet, what will be the output if the target method returns "Hello"?
@Around("execution(* com.example.service.*.*(..))")
public Object log(ProceedingJoinPoint pjp) throws Throwable {
  System.out.println("Before");
  Object result = pjp.proceed();
  System.out.println("After");
  return result + " World";
}
AHello World Before After
BBefore After Hello World
CBefore Hello After World
DBefore After Hello
Step-by-Step Solution
Solution:
  1. Step 1: Trace the advice execution order

    Prints "Before", then calls original method returning "Hello", then prints "After".
  2. Step 2: Analyze the returned value

    Returns original result plus " World", so final returned string is "Hello World".
  3. Final Answer:

    Before After Hello World -> Option B
  4. Quick Check:

    @Around prints before and after, returns modified result [OK]
Quick Trick: Remember @Around runs code before and after proceed() call [OK]
Common Mistakes:
  • Assuming original method output prints automatically
  • Confusing order of print statements
  • Not adding " World" to result

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes