Bird
0
0

Given the following code snippet, what will be printed when service.process() is called?

medium📝 component behavior Q13 of 15
Spring Boot - Aspect-Oriented Programming
Given the following code snippet, what will be printed when service.process() is called?
@Aspect
@Component
public class LoggingAspect {
  @Before("execution(* com.example.service.Service.process(..))")
  public void beforeProcess() {
    System.out.println("Before process");
  }
}

@Service
public class Service {
  public void process() {
    System.out.println("Processing");
  }
}
ABefore process\nProcessing
BProcessing\nBefore process
CBefore process
DProcessing
Step-by-Step Solution
Solution:
  1. Step 1: Understand @Before advice execution timing

    @Before advice runs before the matched method, so "Before process" prints first.
  2. Step 2: Analyze method call output

    Then the actual method prints "Processing" after the advice.
  3. Final Answer:

    Before process\nProcessing -> Option A
  4. Quick Check:

    @Before prints first, then method output [OK]
Quick Trick: @Before prints before method output [OK]
Common Mistakes:
  • Assuming method prints before advice
  • Thinking advice replaces method output
  • Ignoring advice execution order

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes