15. req.getSession().setAttribute("key", new X());
16. req.getSession().setAttribute("key", new X());
17. req.getSession().setAttribute("key", "x");
18. req.getSession().removeAttribute("key");
public void valueBound(HttpSessionBindingEvent event){
System.out.println("B");
}
public void valueUnbound(HttpSessionBindingEvent event){
System.out.println("UB");
}
answer is BBUBUB
I think it is quite clear, line 15 and 16 add two attributes, so valueBound() method is called, which prints B couple of times.
With line 17 you replace a value in the attribute, so valueUnbound is called, and it prints UB.
With line 18 you remove the attribute, and so UB gets printed.
The only point important here is that when you replace a value of a attribute, only valueUnbound() is called.
thankz n regards,
puneet