wood burning stoves 2.0*
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes question from ejbcertificate mock exam Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "question from ejbcertificate mock exam" Watch "question from ejbcertificate mock exam" New topic
Author

question from ejbcertificate mock exam

trupti nigam
Ranch Hand

Joined: Jun 21, 2001
Posts: 613
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

Joined: Nov 14, 2001
Posts: 53
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...
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: question from ejbcertificate mock exam
 
Similar Threads
Boolean declaration and initialization
Interface problem
Compilation fails
Casting and Interfacses
public void onMessage(TextMessage msg){}