This week's book giveaway is in the Features new in Java 9 forum.
We're giving away four copies of Java 9 Revealed and have Kishori Sharan on-line!
See this thread for details.
Win a copy of Java 9 Revealed this week in the Features new in Java 9 forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

implements a listener  RSS feed

 
tony wang
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Question #12:
Given that you have a class that implements HttpSessionAttributeListener with only the following methods:
public void attributeAdded(HttpSessionBindingEvent se){
//do something here}
public void attributeRemoved(HttpSessionBindingEvent se){
//do something here}
What is the result of compiling/executing this code?
A Compiles but will not do anything
B Code would work if HttpSessionBindingListener was implemented
C Code would only work in a Tag class
D Code will not compile
The answer is D ->Error takes place as method: attributeReplaced(HttpSessionBindingEvent se) is not defined.
But I still can't figure out why. Just because the class implements a listener interface
 
tony wang
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
aw, right. HttpSessionAttributeListener is an abstract interface
 
Madhav Lakkapragada
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
aw, right. HttpSessionAttributeListener is an abstract interface
What is an abstract interface......
- madhav
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HttpSessionAttributeListener is an interface. So u have to implement all its methods. There are 3 methods and only 2 are implemented ..so will not compile
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!