Check my answers Considering a class that implements a listener, which are true? a) The event handling method is passed a copy of the Event that occured.- false passesd as ref ??? b) It is not appropriate to extend an Adapter class.- true -not necessary to do so becoz adapterclass alredy implement the interface c) You need only implement the methods you want to handle, even if there are more defined in the interface.- false
"Considering a class that implements a listener, which are true?" a) The event handling method is passed a copy of the Event that occurred.- false passed as ref ??? This must be interpreted as a "copy of the reference to the Event". This part of the test is not about anything but event handling so... Yes, the method is passed a reference to the event (ActionEvent, WindowEvent...)
---------------------------------------- b) It is not appropriate to extend an Adapter class.- true -not necessary to do so becoz adapterclass already implement the interface Just the opposite is true. It is imperative to extend the adapter class for it to be of any use. While it implements all the methods required by the listener interface, these methods don't do anything but return right back. They are meant to be OVERRIDDEN as necessary. because...
------------ c) You need only implement the methods you want to handle, even if there are more defined in the interface.- false
TRUE. See above. For example the WindowListener interface requires seven (count them!) methods to be implemented. If you are only interested in one (like windowClosing() ), then that's the one you'll have to override in the class that extends WindowAdapter.
Tony Alicea Senior Java Web Application Developer, SCPJ2, SCWCD
Tony, I think you're assuming that the class is extending an Adapter. While that's certainly a valid approach, it's not the only one - the class can also implement the listener directly without an adapter. So, my answers: (A) True. I agree, they almost certainly meant "copy of the reference". (B) False. It's not required, but it's certainly possible, and in many cases it's the preferred method. (C) False. You must provide some sort of implementation for all methods in the interface, even if the implementation does not do anything. If you do this by extending an adapter, fine, but you have implemented the methods by your decision to extend the adapter. If you don't use an adapter, then you must implement each method directly. One way or another, all methods in the interface must have some form of implementation. Technically, I suppose C could be true if you allow that the class could also be abstract, but I doubt that's what they meant. I know that this is basically yet another argument over semantics but I do think this is the way the question was intended. Obviously this may be another point where we agree to disagree.
"I'm not back." - Bill Harding, Twister
I can't renounce my name. It's on all my stationery! And hinted in this tiny ad: