aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes AWT Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "AWT " Watch "AWT " New topic
Author

AWT

Richard Wilson
Ranch Hand

Joined: Jan 12, 2002
Posts: 57
An application consists of a set of user interfaces & the various
operations are to be performed based on the various user invoked
events. Which of the following are true for the above application
(a) Extending Adapter classes is not suitable
(b) Some listener interface must be implemented
(c) If a particular event listener is implemented only the methods of
interest to us need to be implemented
(d) Multiple event listeners can be added to a single component
(e) The order in which the events are processed is the order in which
the listeners are added
Ans:a,d
It is a quite strange why a is right?


Richard Wilson
Rob Ross
Bartender

Joined: Jan 07, 2002
Posts: 2205
I would say b & d are correct. Where is this question from? I've learned that a lot of these test questions are just plain wrong.
I suppose a could be correct under certain conditions, but based on the really vauge description of the application, I can't see how extending adapter classes wouldn't be appropriate. If you use an adapter as an annonymous class, that's extending an adapter and this happens all the time.
So I also don't see why a is wrong.


Rob
SCJP 1.4
Rajinder Yadav
Ranch Hand

Joined: Jan 18, 2002
Posts: 178
ans a would seem to be incorrect because the q say many events are to be handled by the app, in which case cluttering you code with many anonymous "adopter" classes that require to be overridded makes the code hard to read if not maintain.
Adapter classes don't provide any functionality, and since you need to define event handlers it seems absurd to use adapter classes that don't do anything.
[ February 18, 2002: Message edited by: Rajinder Yadav ]

<a href="http://www.rajindery.com" target="_blank" rel="nofollow">Rajinder Yadav</a><p>Each problem that I solved became a rule which served afterwards to solve other problems. --Rene Descartes
Rajinder Yadav
Ranch Hand

Joined: Jan 18, 2002
Posts: 178
Rob I agree with you that the ans should also be b & d
Rob Ross
Bartender

Joined: Jan 07, 2002
Posts: 2205
On the contrary, adapter classes help keep your code uncluttered.
If you want to attach a mouse listener to a component, you could do this:

but if all you really want is to handle a mouseClicked event, this is a lot of typing. A MouseAdapter would be more useful in this case:
Rajinder Yadav
Ranch Hand

Joined: Jan 18, 2002
Posts: 178
Rob what I stated in my previous post was that if you need to define "many" of these handlers that the adapter class does nothing for, then having to define handle function that actually do something would result in cluttered hard to read code that uses adaptets which you end up defining/overriding the methods for.
Using your MouseListener, try to think of a realword app that actaully does something for each of these events, would you use adapter classes when each event required something to be done, I don't think you would, would you!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: AWT
 
Similar Threads
Javacap mock test que-27
JavaCaps mock 1 Q:27
Few Tricky Ques.
Listners
listeners