• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Jj Roberts
  • Carey Brown
Bartenders:
  • salvin francis
  • Frits Walraven
  • Piet Souris

question from ejbcertificate mock exam

 
Ranch Hand
Posts: 644
1
  • 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
 
cowbird
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...
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic