Event Handling MCQ

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 20

Unit -III Event Handling

CO-3 Develop programs to handle events in Java Programming


MCQ question bank

Sr. Question Bloom Marks


No Level
1. Which of these packages contains all the classes and methods required for even R 1
handling in Java?
a) java.applet
b) java.awt
c) java.event
d) java.awt.event

Answer: d
Explanation: Most of the event to which an applet response is generated by a user.
Hence they are in Abstract Window Kit package, java.awt.event.
2. What is an event in delegation event model used by Java programming language? R 1
a) An event is an object that describes a state change in a source
b) An event is an object that describes a state change in processing
c) An event is an object that describes any change by the user and system
d) An event is a class used for defining object, to create events

Answer: a
Explanation: An event is an object that describes a state change in a source.
3. Which of these methods are used to register a keyboard event listener? A 1
a) KeyListener()
b) addKistener()
c) addKeyListener()
d) eventKeyboardListener()

Answer: c
Explanation: None.

4. Which of these methods are used to register a mouse motion listener? R 1


a) addMouse()
b) addMouseListener()
c) addMouseMotionListner()
d) eventMouseMotionListener()

Answer: c
Explanation: None.
5. What is a listener in context to event handling? U 1
a) A listener is a variable that is notified when an event occurs
b) A listener is a object that is notified when an event occurs
c) A listener is a method that is notified when an event occurs
d) None of the mentioned

Answer: b
Explanation: A listener is a object that is notified when an event occurs. It has two
major requirements first, it must have been registered with one or more sources to
receive notification about specific event types, and secondly it must implement
methods to receive and process these notifications.
6. Event class is defined in which of these libraries? R 1
a) java.io
b) java.lang
c) java.net
d) java.util

Answer: d
Explanation: None.

7. Which of these methods can be used to determine the type of event? U 1


a) getID()
b) getSource()
c) getEvent()
d) getEventObject()

Answer: a
Explanation: getID() can be used to determine the type of an event.

8. Which of these class is super class of all the events? U 1


a) EventObject
b) EventClass
c) ActionEvent
d) ItemEvent

Answer: a
Explanation: EventObject class is a super class of all the events and is defined in
java.util package.
9 Which of these events will be notified if scroll bar is manipulated? U 1
a) ActionEvent
b) ComponentEvent
c) AdjustmentEvent
d) WindowEvent

Answer: c
Explanation: AdjustmentEvent is generated when a scroll bar is manipulated.
10 Which of these events will be generated if we close an applet’s window? U 1
a) ActionEvent
b) ComponentEvent
c) AdjustmentEvent
d) WindowEvent

Answer: d
Explanation: WindowEvent is generated when a window is activated, closed,
deactivated, deiconfied, iconfied, opened or quit.
11 Which of these events is generated when a button is pressed? U 1
a) ActionEvent
b) KeyEvent
c) WindowEvent
d) AdjustmentEvent

Answer: a
Explanation: Action event is generated when a button is pressed, a list item is double-
clicked or a menu item is selected.
12 Which of these methods can be used to obtain the command name for invoking R 1
ActionEvent object?
a) getCommand()
b) getActionCommand()
c) getActionEvent()
d) getActionEventCommand()

Answer: b
Explanation: None.
13 Which of these are integer constants defined in ActionEvent class? R 1
a) ALT_MASK
b) CTRL_MASK
c) SHIFT_MASK
d) All of the mentioned
Answer: d
Explanation: Action event defines 4 integer constants ALT_MASK, CTRL_MASK,
SHIFT_MASK and ACTION_PERFORMED
14 Which of these methods can be used to know which key is pressed? R 1
a) getKey()
b) getModifier()
c) getActionKey()
d) getActionEvent()

Answer: b
Explanation: The getModifiers() methods returns a value that indicates which
modifiers keys (ALT, CTRL, META, SHIFT) were pressed when the event was
generated.
15 Which of these events is generated by scroll bar? R 1
a) ActionEvent
b) KeyEvent
c) WindowEvent
d) AdjustmentEvent
Answer: d
Explanation: None.
16 Which of these methods can be used to determine the type of adjustment event? U 1
a) getType()
b) getEventType()
c) getAdjustmentType()
d) getEventObjectType()

Answer: c
Explanation: None.
17 Which of these methods can be used to know the degree of adjustment made by the U 1
user?
a) getValue()
b) getAdjustmentType()
c) getAdjustmentValue()
d) getAdjustmentAmount()

Answer: a
Explanation: The amount of the adjustment can be obtained from the getvalue()
method, it returns an integer value corresponding to the amount of adjustment made.

18 Which of these constant value will change when the button at the end of scroll bar R 1
was clicked to increase its value?
a) BLOCK_DECREMENT
b) BLOCK_INCREMENT
c) UNIT_DECREMENT
d) UNIT_INCREMENT

Answer: d
Explanation: UNIT_INCREMENT VALUE will change when the button at the end of
scroll bar was clicked to increase its value.
19 Which of these events is generated when the size of an event is changed? R 1
a) ComponentEvent
b) ContainerEvent
c) FocusEvent
d) InputEvent

Answer: a
Explanation: A ComponentEvent is generated when the size, position or visibility of a
component is changed.
20 Which of these events is generated when the component is added or removed? R 1
a) ComponentEvent
b) ContainerEvent
c) FocusEvent
d) InputEvent

Answer: b
Explanation: A ContainerEvent is generated when a component is added to or
removed from a container. It has two integer constants COMPONENT_ADDED &
COMPONENT_REMOVED.
21 Which of these methods can be used to obtain the reference to the container that R 1
generated a ContainerEvent?
a) getContainer()
b) getContainerCommand()
c) getActionEvent()
d) getContainerEvent()

Answer: d
Explanation: None.
22 Which of these methods can be used to get reference to a component that was U 1
removed from a container?
a) getComponent()
b) getchild()
c) getContainerComponent()
d) getComponentChild()

Answer: b
Explanation: The getChild() method returns a reference to the component that was
added to or removed from the container.
Which of these are integer constants of ComponentEvent class?
a) COMPONENT_HIDDEN
b) COMPONENT_MOVED
c) COMPONENT_RESIZE
d) All of the mentioned
23 Which of these are integer constants of ComponentEvent class? R 1
a) COMPONENT_HIDDEN
b) COMPONENT_MOVED
c) COMPONENT_RESIZE
d) All of the mentioned
Answer: d
Explanation: The component event class defines 4 constants
COMPONENT_HIDDEN, COMPONENT-MOVED, COMPONENT-RESIZE and
COMPONENT-SHOWN.
24 Which of these methods can be used to know the type of focus change? U 1
a) typeFocus()
b) typeEventFocus()
c) isTemporary()
d) isPermanent()

Answer: c
Explanation: There are two types of focus events – permanent and temporary. The
isTemporary() method indicates if this focus change is temporary, it returns a Boolean
value.

25 Which of these is superclass of ContainerEvent class? R 1


a) WindowEvent
b) ComponentEvent
c) ItemEvent
d) InputEvent

Answer: b
Explanation: ContainerEvent is superclass of ContainerEvent, FocusEvent, KeyEvent,
MouseEvent and WindowEvent.
26 Which of these events is generated when the window is closed? U 1
a) TextEvent
b) MouseEvent
c) FocusEvent
d) WindowEvent

Answer: d
Explanation: A WindowEvent is generated when a window is opened, close, activated
or deactivated.
27 Which of these methods can be used to obtain the coordinates of a mouse?a) R 1
a)getPoint()
b) getCoordinates()
c) getMouseXY()
d) getMouseCordinates()

Answer: a
Explanation: getPoint() method can be used to obtain coordinates of a mouse,
alternatively we can use getX() and getY() methods for x and y coordinates of mouse
respectively
28 Which of these methods can be used to change location of an event? R 1
a) ChangePoint()
b) TranslatePoint()
c) ChangeCordinates()
d) TranslateCordinates()

Answer: b
Explanation: None.
29 Which of these are integer constants of TextEvent class? A 1
a) TEXT_CHANGED
b) TEXT_FORMAT_CHANGED
c) TEXT_VALUE_CHANGED
d) TEXT_sIZE_CHANGED

Answer: c
Explanation: TextEvent defines a single integer constant
TEXT_VALUE_CHANGED.
30 Which of these methods is used to obtain the object that generated a WindowEvent? U 1
a) getMethod()
b) getWindow()
c) getWindowEvent()
d) getWindowObject()

Answer: b
Explanation: getWindow()methods is used to obtain the object that generated a
WindowEvent.
31 MouseEvent is subclass of which of these classes? U 1
a) ComponentEvent
b) ContainerEvent
c) ItemEvent
d) InputEvent

Answer: d
Explanation: InputEvent is subclass of which of these classes
32 Which of these methods is used to get x coordinate of the mouse? U 1
a) getX()
b) getXCoordinate()
c) getCoordinateX()
d) getPointX()

Answer: a
Explanation: getX() and getY() are used to obtain X AND Y coordinates of the
mouse.
33 Which of these are constants defined in WindowEvent class? U 1
a) WINDOW_ACTIVATED
b) WINDOW_CLOSED
c) WINDOW_DEICONIFIED
d) All of the mentioned

Answer: d
Explanation: WindowEvent class defines 7 constants – WINDOW_ACTIVATED,
WINDOW_CLOSED, WINDOW_OPENED, WINDOW_DECONIFIED,
WINDOW_CLOSING, WINDOW_DEACTIVATED, WINDOW_ICONIFIED.
34 Which of these is superclass of WindowEvent class? U 1
a) WindowEvent
b) ComponentEvent
c) ItemEvent
d) InputEvent

Answer: b
Explanation: ComponentEvent is superclass of ContainerEvent, FocusEvent,
KeyEvent, MouseEvent and WindowEvent.
35 Which of these interfaces handles the event when a component is added to a U 1
container?
a) ComponentListener
b) ContainerListener
c) FocusListener
d) InputListener

Answer: b
Explanation: The ContainerListener defines methods to recognize when a component
is added to or removed from a container.
36 Which of these interfaces define a method actionPerformed()? U 1
a) ComponentListener
b) ContainerListener
c) ActionListener
d) InputListener

Answer: c
Explanation: ActionListener defines the actionPerformed() method that is invoked
when an adjustment event occurs.
37 Which of these interfaces define four methods? R 1
a) ComponentListener
b) ContainerListener
c) ActionListener
d) InputListener

Answer: a
Explanation: ComponentListener defines four methods componentResized(),
componentMoved(), componentShown() and componentHidden().
38 Which of these interfaces define a method itemStateChanged()? U 1
a) ComponentListener
b) ContainerListener
c) ActionListener
d) ItemListener

Answer: d
Explanation: ItemListener interfaces define a method itemStateChanged().
39 Which of these methods will respond when you click any button by mouse? R 1
a) mouseClicked()
b) mouseEntered()
c) mousePressed()
d) all of the mentioned

Answer: d
Explanation: when we click a button, first we enter the region of button hence
mouseEntered() method responds then we press the button which leads to respond
from mouseClicked() and mousePressed().
40 Which of these methods will be invoked if a character is entered? U 1
a) keyPressed()
b) keyReleased()
c) keyTyped()
d) keyEntered()

Answer: c
Explanation: keyTyped() methods will be invoked if a character is entered.
41 Which of these methods is defined in MouseMotionAdapter class? R 1
a) mouseDragged()
b) mousePressed()
c) mouseReleased()
d) mouseClicked()

Answer: a
Explanation: The MouseMotionAdapter class defines 2 methods – mouseDragged()
and mouseMoved.
42 Which of these is a superclass of all Adapter classes? U 1
a) Applet
b) ComponentEvent
c) Event
d) InputEvent

Answer: a
Explanation: All Adapter classes extend Applet class.

43 The Following steps are required to perform Implement the Listener interface and U 1
overrides its methods Register the component with the Listener
(a) Exception Handling
(b) String Handling
(c) Event Handling
(d) None of the above

Answer: c
Explanation: Event Handling Listener interface and overrides its methods Register the
component with the Listener .
44 In which places can put the event handling code R 1
(a) Same class
(b) Other class
(c) Annonymous class
(d) All mentioned above

Answer: d
Explanation: All class can put the event handling code
45 To use the ActionListener interface it must be implemented by a class there are R 1
several ways to do that find in the following?
(a) Creating a new class
(b) using the class the graphical component
(c) an anonymous inner class
(d) All mentioned above

Answer: d
Explanation: Creating a new class and using the class the graphical component, an
anonymous inner class use the ActionListener interface
46 The ActionListener interface is not used for handling action events? U 1
(a) True
(b) False

Answer: b
Explanation: The ActionListener interface is used for handling action events.
47 The ActionListener interface is used for handling action events, For example, it's used A 1
by a
(a) JButton
(b) JCheckbox
(c) All of these
(d) JMenuItem
Answer: c
Explanation: ActionListener interface is used for handling action events by JButton,
JCheckbox, JMenuItem.
48 Which class is used for this Processing Method processActionEvent( )? U 1
(a) Button,List,MenuItem
(b) Button,Checkbox,Choice
(c) Scrollbar,Component,Button
(d) None of the above

Answer: a
Explanation: Button,List,MenuItem class is used for this Processing Method
processActionEvent( ).
49 In Graphics class Which method is used to set the graphics current color to the U 1
specified color?
(a) public abstract void setFont(Font font)
(b) public abstract void setColor(Color c)
(c) public abstract void drawString(String str, int x, int y)
(d) None of the above

Answer: b
Explanation: public abstract void setColor(Color c) class Which method is used to set
the graphics current color to the specified color.
50 Which of the following method is used to determine the type of adjustment event? A 1
(a) getType( )
(b) getEventType( )
(c) getAdjustmentType( )
(d) getEventObjectType( )

Answer: c
Explanation: getAdjustmentType( ) method is used to determine the type of
adjustment event.
51 TextField generates event_______________ R 1
(a) ActionEvent,ItemEvent
(b) ActionEvent, TextEvent
(c) ScrollEvent,TextEvent
(d) ActionEvent, ScrollEvent
Answer: b
Explanation: ActionEvent, TextEvent are generated by text field.
52 void keyTyped(KeyEvent ke) called when a key on the keyboard is . U 1
(a) pressed and then released.
(b) pressed
(c) released
(d) none of the above

Answer: a
Explanation: pressed and then released key on the keyboard is void
keyTyped(KeyEvent ke).
53 The signature for the registration method for a ActionEvent should be . R 1
(a) public void addActionListener(ActionEvent L)
(b) public void setAction(ActionListener L)
(c) public void setActionListener(ActionListener L)
(d) public void addActionListener(ActionListener L)

Answer: d
Explanation: public void addActionListener(ActionListener L) is used for the
registration method for a ActionEvent.
54 Name the method defined in EventObject class that returns the object generated from R 1
the event.
(a) getEvent( )
(b) getObject( )
(c) getId( )
(d) getSource( )

Answer: d
Explanation: getSource( ) method defined in EventObject class that returns the object
generated from the event.
55 The MouseListener interface is used to make mouse handling. R 1
(a) True
(b) False

Answer: a
Explanation: The MouseListener interface is used to make mouse handling.
56 ActionEvent is applied on R 1
(a) Frame
(b) Checkbox, Choice, List
(c) Scrollbar
(d) Button, TextField, List, Menu

Answer: d
Explanation: ActionEvent is applied on Button, TextField, List, Menu.
57 If we close an applet window events will be generated. R 1
(a) ActionEvent
(b) ComponentEvent
(c) AdjustmentEvent
(d) WindowEvent

Answer: d
Explanation: WindowEvent will be generated by closing an applet window event.
58 Which Listener handles all List related Events? R 1
(a) ItemListener
(b) InputEvent
(c) SelectEvent
(d) ListEvent

Answer: a
Explanation: ItemListener handles all List related Events.
59 How to obtain the command name for invoking ActionEvent? U 1
(a) getCommandName( )
(b) getActionEventCommand( )
(c) getActionCmd( )
(d) getActionCommand( )

Answer: d
Explanation: getActionCommand( ) obtained by invoking ActionEvent.
60 Which of the following is not the method of handling window event? R 1
(a) void windowClosed(WindowEvent we)
(b) void windowClosing(WindowEvent we)
(c) void windowAfterClosing(WindowEvent we)
(d) All of these

Answer: c
Explanation: void windowAfterClosing(WindowEvent we) is not the method of
handling window event.
61 What is the use of String getActionCommand( ) method of ActionEvent class? A 1
(a) to obtain the label (caption) of Button
(b) to obtain the reference of Button
(c) to obtain object of Button
(d) to obtain the label (caption) and object of Button

Answer: a
Explanation: Use of String getActionCommand( ) method of ActionEvent class for
obtain the label (caption) of Button .
62 Which is true about an anonymous inner class? U 1
a)It can extend exactly one class and implement exactly one interface.
b)It can extend exactly one class and can implement multiple interfaces.
c)It can extend exactly one class or implement exactly one interface.
d)It can implement multiple interfaces regardless of whether it also extends a class.

Answer: C
Explanation: Option C is correct because the syntax of an anonymous inner class
allows for only one named type after the new, and that type must be either a single
interface (in which case the anonymous class implements that one interface) or a
single class (in which case the anonymous class extends that one class).
63 Which is true about a method-local inner class? U 1
a)It must be marked final.
b)It can be marked abstract.
c)It can be marked public.
d)It can be marked static.

Answer: Option B
Explanation:Option B is correct because a method-local inner class can be abstract,
although it means a subclass of the inner class must be created if the abstract class is
to be used (so an abstract method-local inner class is probably not useful).

64 Which statement is true about a static nested class? A 1


a)You must have a reference to an instance of the enclosing class in order to
instantiate it.
b)It does not have access to nonstatic members of the enclosing class.
c)It's variables and methods must be static.
d)It must extend the enclosing class.

Answer: b
Explanation:Option b) is correct because a static nested class is not tied to an instance
of the enclosing class, and thus can't access the nonstatic members of the class (just as
a static method can't access nonstatic members of a class).
65 Which constructs an anonymous inner class instance? U 1
a)Runnable r = new Runnable() { };
b)Runnable r = new Runnable(public void run() { });
c)Runnable r = new Runnable { public void run(){}};
d)System.out.println(new Runnable() {public void run() { }});

Answer: d
Explanation:d is correct. It defines an anonymous inner class instance, which also
means it creates an instance of that new anonymous class at the same time. The
anonymous class is an implementer of the Runnable interface, so it must override
the run() method of Runnable.
66 When the component is added or removed ? Which of these events is generated ? U 1
(a) ComponentEvent (b) ContainerEvent
(c) FocusEvent (d) InputEvent

Answer: (b) ContainerEvent


Explanation:A ContainerEvent is generated when a component is added to or
removed from a container.
67 Which is the method used for WindowsClosing Event? U 1
(a)windowOpened() (b)windowClosed()
(c ) windowClosing() (d) windowDeactivated()

Answer: (b)windowClosed()
Explanation: windowClosed()method used for WindowsClosing Event.

68 _____event is generated when computer gains or losses input focus. U 1


(a) ComponentEvent (b) ContainerEvent
(c) FocusEvent (d) InputEvent

Answer: (c) FocusEvent


Explanation: FocusEvent is generated when computer gains or losses input focus

69 FocusEvent is subclass of which of these classes? U 1


(a) ComponentEvent (b) ContainerEvent
(c) ItemEvent (d) InputEvent
Answer: (a) ComponentEvent
Explanation: FocusEvent is subclass of ComponentEvent.
70 ___ can be used to know the type of focus change. U 1
(a) typeFocus() (b) typeEventFocus()
(c) isTemporary() (d) isPermanent()

Answer: (c) isTemporary()


Explanation: There are two types of focus events – permanent and temporary. The
isTemporary() method indicates if this focus change is temporary, it returns a Boolean
value.

71 ____ is superclass of Container Event class. R 1


(a) WindowEvent (b) ComponentEvent
(c) ItemEvent (d) InputEvent

Answer: C
Explanation: ContainerEvent is superclass of ContainerEvent, FocusEvent, KeyEvent,
MouseEvent and WindowEvent..

72 Which of the following method can be used to obtain the coordinates of a mouse? R 1
(a) getPoint() (b) getCoordinates()
(c) getMouseXY() (d) getMouseCordinates()

Answer: (c) getMouseXY()


Explanation: getPoint() method can be used to obtain coordinates of a mouse,
alternatively we can use getX() and getY() methods for x and y coordinates of mouse
respectively.
73 _____method can be used to change location of an event. R 1
(a) ChangePoint() (b) TranslatePoint()
(c) ChangeCordinates() (d) TranslateCordinates()

Answer: (b) TranslatePoint()

Explanation: TranslatePoint()method can be used to change location of an event.

74 _____ is used to obtain the object that generated a Window Event. R 1


(a) getMethod() (b) getWindow()
(c) getWindowEvent() (d) getWindowObject()

Answer: (b) getWindow()


Explanation: getWindow() is used to obtain the object that generated a Window
Event
75 MouseEvent is subclass of which of these classes? U 1
(a) ComponentEvent (b) ContainerEvent
(c) ItemEvent (d) InputEvent

Answer: (d) InputEvent


Explanation: MouseEvent is subclass of InputEvent .
76 ___ method is used to get x coordinate of the mouse. R 1
(a) getXO (b) getXCoordinateO
(c) getCoordinateXO (d) getPointXO

Answer: (a) getX()


Explanation:: getX() and getY() are used to obtain X AND Y coordinates of the
mouse.
77 When a component is added to a container which of these interfaces handles the R 1
event?
(a) ComponentListener (b) ContainerListener
(c) FocusListener (d) InputListener
Answer: (b) ContainerListener
Explanation: The ContainerListener defines methods to recognize when a component
is added to or removed from a container.
78 ___ interface define a method actionPerformed(). R 1
(a) ComponentListener (b) ContainerListener
(c) ActionListener (d) InputListener

Answer: (c) ActionListener


Explanation: ActionListener defines the actionPerformed() method that is invoked
when an adjustment event occurs.
79 Which method is used to set an icon to an Label? U 1
(a) setIcon() (b)setImage()
(c) getImage() (d)setIconImage()

Answer: (a) setIcon()


Explanation: setIcon()method is used to set an icon to an Label.
80 __ interfaces define a method itemStateChanged() R 1
(a) ComponentListner (b)ContainerListener
(c) ActionListener (d) ItemListener

Answer: (d) ItemListener


Explanation: ItemListener interfaces define a method itemStateChanged().
81 Which method from the following methods will respond when you click any button R 1
by mouse?
(a) mouseClicked() (b) mouseEntered()
(c) mousePressed() (d) All of the mentioned
Answer: (d) All of the mentioned
Explanation: when we click a button, first we enter the region of button hence
mouseEntered() method responds then we press the button which leads to respond
from mouseClicked() and mousePressed.
82 _____methods is defined in MouseMotionAdapter class. R 1
(a) mouseDragged() (b) mousePressed()
(c) mouseReleased() (d)mouseClicked()
Answer: (a) mouseDragged()
Explanation: The MouseMotionAdapter class defines 2 methods – mouseDragged()
and mouseMoved.
83 Which method is used to have rollover icon? U 1
(a)setDisabledIcon() (b)setDisabled()
(c) setRollover() (d)setRolloverIcon()

Answer: (d)setRolloverIcon()
Explanation: setRolloverIcon()method is used to have rollover icon.
84 ______is the superclass of all Adapter classes. R 1
(a) Applet (b) ComponentEvent
(c) Event (d) InputEvent
Answer: (a) Applet
Explanation: All Adapter classes extend Applet class.
85 In Java, events are all the activities that occur between: R 1
(a)The user (b) The application
(c) Both (a) and (b) (d) None of the above

Answer: (c) Both (a) and (b)


Explanation: events are all the activities that occur between the user and application.
86 EventObject class belongs to: U 1
(a) java.util (b) java.awt
(c) java.lang (d) java.sql

Answer: (b) java.awt


Explanation: EventObject class belongs to java.awt
87 The Component class is an abstract class and so its_______are used to create U 1
components.
(a) Subclasses (b)Superclasses (c)Both (a) and (b) (d)None of these.

Answer: (c)Both (a) and (b)


Explanation: The Component class is an abstract class and so its Subclasses and
Superclasses are used to create components.
88 The_______interface is used to handle the menu events. U 1
(a) ContainerListener (b) FocusListener
(c) ActionListener (d) WindowListner

Answer: (c) ActionListener


Explanation: The Event listener represent the interfaces responsible to handle events.
Java provides us various Event listener classes but we will discuss those which are
more frequently used.
89 An event is generated when the internal state of the event source is_____ U 1
(a) Not changed (b) Changed
(c) Either changed or not (d) None of these.

Answer: (b) Changed


Explanation: Change in the state of an object is known as event i.e. event describes
the change in state of source.
90 The_____ interface handles list events: R 1
(a) ContainerListener (b) ItemListener
(c) FocusListener (d) ActionListener

Answer: (d) ActionListener


Explanation: The Event listener represent the interfaces responsible to handle events.
Java provides us various Event listener classes but we will discuss those which are
more frequently used.
91 What is a listener in context to event handling? R 1
(a) A listener is a variable that is notified when an event occurs
(b) A listener is a object that is notified when an event occurs
(c) A listener is a method that is notified when an event occurs
(d) None of the mentioned

Answer: (b) A listener is a object that is notified when an event occurs


Explanation: A listener is a object that is notified when an event occurs. It has two
major requirements first, it must have been registered with one or more sources to
receive notification about specific event types, and secondly it must implement
methods to receive and process these notifications.
92 Which of the following are true? R 1
(a) A TextField object may generate an ActionEvent.
(b) A Button object may generate an ActionEvent.
(c) A MenuItem object may generate an ActionEvent.
(d) All of above

Answer: (d) All of above


Explanation: All of above may generate an ActionEvent.
93 When two or more objects are added as. listeners for the same event, which listener is R 1
first invoked to handle the event?
(a) The first object that was added as listener.
(b) The last object that was added as listener.
(c) There is no way to determine which listener will be invoked first.
(d) It is impossible to have more than one listener for a given event.

Answer: (c) There is no way to determine which listener will be invoked first.
Explanation: When two or more objects are added as. listeners for the same event,
There is no way to determine which listener will be invoked first.
94 Which of the following are true? R 1
(a) The MouseListener interface defines methods for handling mouse clicks.
(b) The MouseMotionListener interface defines methods for handling mouse
clicks.
(c) The ActionListener interface defines methods for handling the clicking of a
button.
(d) Option (a) and (c)

Answer: (d) Option (a) and (c)


Explanation: Both are correct
95 Suppose that you want to have an object "eh" to handle the TextEvent of a TextArea R 1
object. How should you add eh as the event handler to it ?
(a) t.addTextListener(eh); (b) eh.addTextListener(t);
(c) addTextListener(eh.t); (d) addTextListener(t,eh);

Answer: (d) addTextListener(t,eh)


Explanation: addTextListener(t,eh) you add eh as the event handler to it.
96 What is the preferred way to handle an object's events in Java 2? R 1
(a) Override the object's handleEvent( ) method.
(b) Add one or more event listeners to handle the events.
(c) Have the object override its processEvent() methods
(d) Have the object override its dispatchEvent() methods.

Answer: (a)
Explanation: Override the object's handleEvent( ) method.
97 Which of the following are true? U 1
(a) A component may handle its own events by adding itself as an event listener.
(b) A component may handle its own events by overriding its event-dispatching
method.
(c) A component may not handle its own events.
(d) Option (a) and (b)

Answer: (a)
Explanation: A component may handle its own events by adding itself as an event
listener.
98 The event delegation model, introduced in release 1.1 of the JDK, is fully compatible R 1
with the event model.
(a) True (b) False

Answer: (b) False


Explanation: As earlier event model with jdk1. 0 only components classes have event
handling methods and so no other object can handle events.
99 A component subclass that has executed enableEvents( ) to enable processing of a A 1
certain kind of event cannot also use an adapter as a listener for the same kind of
event.
(a) True (b) False

Answer: (b) False


Explanation: A component subclass that has executed enableEvents( ) to enable
processing of a certain kind of event cannot also use an adapter as a listener for the
different kind of event.
100 What is a listener in context to event handling? A 1
(a) A listener is a variable that is notified when an event occurs.
(b) A listener is a 'object that is notified when an event occurs.
(c) A listener is a method that is notified when an event occurs.
(d) None of the mentioned

Answer: (c) A listener is a method that is notified when an event occurs.


Explanation: A listener is a object that is notified when an event occurs. It has two
major requirements first, it must have been registered with one or more sources to
receive notification about specific event types, and secondly it must implement
methods to receive and process these notifications.

You might also like