Bird
0
0

Given this aspect code snippet, what will be printed when myService.process() is called?

medium📝 Predict Output Q4 of 15
Spring Boot - Aspect-Oriented Programming
Given this aspect code snippet, what will be printed when myService.process() is called?
@Aspect
@Component
public class LoggingAspect {
  @Before("execution(* com.example.MyService.process(..))")
  public void logBefore() {
    System.out.println("Start processing");
  }
}
ANo output
BStart processing followed by method output
CStart processing
DCompilation error
Step-by-Step Solution
Solution:
  1. Step 1: Understand the @Before advice

    The method logBefore() runs before the process() method and prints "Start processing".
  2. Step 2: Determine output on calling process()

    Only "Start processing" is printed before process() runs; no other prints shown.
  3. Final Answer:

    Start processing -> Option C
  4. Quick Check:

    @Before advice prints message before method [OK]
Quick Trick: @Before advice runs before target method [OK]
Common Mistakes:
  • Expecting method output to print automatically
  • Thinking no output occurs
  • Assuming compilation error due to annotation

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes