• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Devaka Cooray
  • Ron McLeod
  • paul wheaton
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Frits Walraven
  • Scott Selikoff

question from ejbcertificate mock exam

 
Ranch Hand
Posts: 644
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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...
 
Your mother was a hamster and your father was a tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic