• 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Listener Ques

 
Ranch Hand
Posts: 216
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Desperado
Posts: 3226
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"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.

 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
It means our mission is in jeapordy! Quick, read this tiny ad!
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic