Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

question from ejbcertificate mock exam

 
trupti nigam
Ranch Hand
Posts: 625
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1.public class GatewayBean implements MessageDrivenBean, MessageListener {
2. public GatewayBean(){}
3. public void ejbCreate(){}
4. public void onMessage(TextMessage msg){}
5. public void ejbRemove(){}
6. public void setMessageDrivenContext(MessageDrivenContext ctx){}
7.}


What will happen when you try to compile the following message driven bean? Assume all packages are correctly imported.

1. Compilation error, incorrect declaration on line 3.
2. Compilation error, incorrect declaration on line 4.
3. The code compiles fine.
4. Compilation error, the GatewayBean class must be declared abstract.
5. Compilation error, the GatewayBean class must be declared final.

The correct answer given is 2..but i think the correct answer should be 3.
The TextMessage is a type of Message so it is valid.

thanks,
trupti
 
Jef Cumps
cowbird
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, there is indeed a syntax error in line 4. Though TextMessage is a kind of Message, the MessageListener interface defines onMessage() with a Message as parameter. It's just like implementing a plain Java interface, you cannot narrow the types... Anybody should be able to call your onMethod() as it is defined in the interface, so with a Message as param. If you define TextMessage as param, that is NOT imlpementing the interface...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic