How have you used HttpSessionBindingListenerTest class in your code ? btw please post sample code which you are trying to use.
Answer to your query lies in your question.
because an HttpSessionAttributeListener is notified any time an attribute is added and the value object will also be notified if it implements an HttpSessionBindingListener.
Read this quote carefully.
Here, it says that Attribute need to implement HttpSessionBindingListener so that valueBound() and other callback methods can be called by
servlet container.
First of all , answer toy your sample code
For this to work, you need to add HttpSessionBindingListenerTest object in Session as attribute.
so , below line should call callback methods of both HttpSessionBindingListener and HTTPSessionAttributeListener.
Now coming to your mock question
At the first, it might seem a bit confusing .. you might question why we need two listener for same thing .. well .. it is not same .....you need to understand and remember the difference between two Listeners in terms of who gets notified or who is the main point of concern.
HTTPSessionAttributeListener allows you to listen when any new attribute is added in [ or existing attribute is removed from] Session. Here, out main context is Session and we want to keep track [ listen] all attributes that are getting added/removed in Session. Session is our main point of concern over which we want to keep an eye [ or ear
].
HttpSessionBindingListener allows you to listen an particular object [ or instance of class] when that object is added in/remove from Session.
For example - I can create an class - UserInfo class which implements HttpSessionBindingListener. Now, when I add object of UserInfo class in HTTP Session, callback methods of HttpSessionBindingListener gets called. So , here , out main point of concern is User Object which get added in Session. We may have number of attributes getting added in [ or removed from ] Session, here, we want to listen only particular objects of a class.
Now, if you add
String value in Session, HttpSessionBindingListener methods shall not get called as String class in
Java do not implement HttpSessionBindingListener.
Now I think you shall be able to answer this question yourself
Since in this question, it is not specified whether 'value' is an object implementing HttpSessionBindingListener or not. value can be any thing - an Integer, String, an object implementing HttpSessionBindingListener .
So , here answer is F (HttpSessionBindingListener and HttpSessionAttributeListener)
Reply back if you have any queries