Bird
0
0

Given this advice code snippet, what will be logged when calculateSum(5, 10) is called?

medium📝 Command Output Q4 of 15
Spring Boot - Aspect-Oriented Programming
Given this advice code snippet, what will be logged when calculateSum(5, 10) is called?
@Before("execution(* com.example.Calculator.calculateSum(..))")
public void logBefore(JoinPoint joinPoint) {
    System.out.println("Starting: " + joinPoint.getSignature().getName());
}
AStarting: calculateSum
BStarting: logBefore
CStarting: com.example.Calculator
DNo output
Step-by-Step Solution
Solution:
  1. Step 1: Understand JoinPoint signature usage

    The joinPoint.getSignature().getName() returns the method name being advised, here calculateSum.
  2. Step 2: Analyze the printed output

    The advice prints "Starting: " plus the method name, so output is "Starting: calculateSum".
  3. Final Answer:

    Starting: calculateSum -> Option A
  4. Quick Check:

    JoinPoint method name = calculateSum [OK]
Quick Trick: joinPoint.getSignature().getName() gives advised method name [OK]
Common Mistakes:
  • Printing advice method name instead of target method
  • Expecting class name instead of method name
  • Assuming no output from @Before advice

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes