🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← 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"));
    }
}
  1. A.Hello asha
  2. B.hello asha
  3. C.HELLO ASHA
  4. 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 →