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.
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...