This week's book giveaway is in the OCPJP forum. We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line! See this thread for details.
What type of bean may contain such code? A. Message-driven bean B. Stateless session bean C. Stateful session bean D. None of the above
I was first thinking this can only happen in entity bean. But then I realize that all other type of bean can actually get the reference component interface of an enity bean via a method argument. Well in that case all type of beans can contain such code. Or can they?
In the example, the EJB object reference is obtained from the EJBContext and not as a method argument. So naturally this code is from an entity bean. Unless it is explicitly mentioned that the reference is passed as a method argument, you should assume that it is from an entity bean, since only they can have primary keys.
According to the question statement as it is formulated, you cannot know for sure that this code snippet really comes from an entity bean. While it is true that primary keys only make sense in the context of entity beans, it is also possible to call getPrimaryKey() on an EJBObject of a session bean but a RemoteException would be thrown at runtime. Since the question statement only says that the code compiles successfully, there is no hint as to how it behaves at runtime, and thus, B and C would be the correct answers. [ June 21, 2004: Message edited by: Valentin Crettaz ]