← Quiz: Spring AOP and Proxies: all 10 questions
Quiz: Spring AOP and Proxies · Question 3 of 10
What does this print? (code)
What does this print?
import java.lang.reflect.*;
interface Greeter { String greet(String name); }
public class Main {
public static void main(String[] args) {
Greeter real = name -> "Hello " + name;
Greeter proxy = (Greeter) Proxy.newProxyInstance(
Greeter.class.getClassLoader(), new Class<?>[]{Greeter.class},
(p, m, a) -> ((String) m.invoke(real, a)).toUpperCase());
System.out.println(proxy.greet("asha"));
}
}
- A.Hello asha
- B.hello asha
- C.HELLO ASHA
- D.Hello ASHA
Answer & explanation
Correct answer: HELLO ASHA
The proxy calls the real method ("Hello asha") and then changes the result to upper case.
Can you get the rest right without peeking?
Take the timed Quiz: Spring AOP and Proxies quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →