0% found this document useful (0 votes)
2 views

Chapter2QB

The document consists of a series of multiple-choice questions and answers related to event handling in Java, covering topics such as event adapters, event listeners, event classes, and the delegation event model. It includes questions about specific interfaces, methods, and constants associated with event handling, as well as the relationships between different event types. The answers provided indicate the correct options for each question, highlighting key concepts in Java's event handling framework.

Uploaded by

ramababhulkar16
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Chapter2QB

The document consists of a series of multiple-choice questions and answers related to event handling in Java, covering topics such as event adapters, event listeners, event classes, and the delegation event model. It includes questions about specific interfaces, methods, and constants associated with event handling, as well as the relationships between different event types. The answers provided indicate the correct options for each question, highlighting key concepts in Java's event handling framework.

Uploaded by

ramababhulkar16
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 16

1. An event adapter can be implemented using ___________.

A. standard adapter C. anonymous inner class adapter


B. inner class adapter D. All of above
Answer: D
2. An event and its corresponding listener is referred to as ____________.
A. an event set C. an event pair
B. an event class D. an event object
Answer: A, C
3. Any event is an instance of _________.
A. java.awt.ActionEvent C. java.awt.Component
B. javax.swing.JComponent D. java.util.EventObject
Answer: D
4. Creating Custom Event Sets Which of the followings are true?
A. By convention, an event class should be named with suffix Event.
B. An event class does not have a no-args constructor, because you must
always specify a source for the event when creating an event.
C. A custom event class must extend java.util.EventObject or a subclass of
java.util.EventObject.
D. A custom event listener interface must extend java.util.EventListener or a
subinterface of java.util.EventListener, and define the signature of the
handlers.
E. A listener interface for a custom event BeatEvent should be named
BeanListener by convention.
F. Answer: ABCDE
5. Which of the following is true?
A. Events can be unicasted (only one listener object is notified of the
event).
B. Events can be multicasted (each object in a list of listeners is notified of
the event).
C. The naming pattern for adding a multicast listener is "public void
add<Event>Listener(<Event>Listener l)"
D. The naming pattern for adding a unicast listener is "public void
add<Event>Listener(<Event>Listener l) throws
TooManyListenersException"
E. A source component must have the appropriate registration and
deregistration methods for adding and removing listeners.
Answer: ABCDE
6. Any listener is an instance of _________.
A. java.util.EventListener C. java.util.EventObject
B. javax.swing.JComponent D. java.awt.ActionListener
Answer:A
7. The signature for the registration method for an ActionEvent should be
__________.
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
8. The constructor which the Text Event class defines.
a. TextEvent(Object source, intevent_type)
b. textevent (Object source, intevent_type)
c. textevent (object Source, float event_type)
d. textevent (Object source, string event_type)
Answer: A
9. In Java an event is an _______which specifies the change of state in the
source.
a. Class c. Int
b. Object d. String
Answer: b
10.The name of the event classes are
a. ActionEvent, ComponentEvent
b. ContainerEvent, FocusEvent
c. ItemEvent, KeyEvent
d. WindowListener, MouseEvent
e. TextEvent
f. All of these
Answer: f
11.Java packages such as ________________ support the Event handling
mechanism.
a. java.util c. java.awt.event
b. java.awt d. All of these
Answer: c
12.Some of the event listener interfaces are_____________
a. ActionListener, ComponentListener
b. ContainerListener, FocusListener
c. ItemListener, KeyListener
d. WindowListener, MouseListener
e. TextListener
f. All of these
Answer: f
13.In Java, events are all the activities that occur between
a. The user c. Both a & b
b. The applications d. None of these
Answer: c
14.Till now, two models have been introduced in Java for
a. Receiving and Processing events
b. Deleting and Processing events
c. Receiving and Deleting events
d. Modifying and Receving events
Answer: a
15.An event is generated whe the internal state of the event source is________
a. Not changed c. Either changed or not
b. Changed d. None of these
Answer: b
16.EventObject class belongs to:
a. java.util c. java.lang
b. java.awt d. java.sql
Answer: b
17.The __________ interface is used to handle the menu events
a. ContainerListener c. ActionListener
b. FocusListener d. WindowListener
Answer: c

18.The ___________ interface handles list events:


a. ContainerListener d. ItemListener
b. FocusListener e. c&d
c. ActionListener
Answer: e
19.The ___________ interface handles choice events:
a. ContainerListener c. ActionListener
b. ItemListener d. WindowListener
Answer: b
20.The ___________ interface is used to handle checkbox events:
a. ContainerListener c. ActionListener
b. ItemListener d. WindowListener
Answer: b
21.The ___________ interface is used to handle button events:
a. ContainerListener c. ActionListener
b. ItemListener d. WindowListener
Answer: c
22.ItemListener is defined by the _____________ method:
a. itemChangedState() c. itemChanged()
b. itemStateChanged() d. itemState()
Answer: b
23.The Delegation Event Model is based on the concept of _____________
a. Source c. Both a & b
b. Listener d. None of these
Answer: c
24.A source generates an event and sends it to ___________ listeners that can
handle the event:
a. One c. One or more
b. Two d. None of these
Answer: a
25._______ generates action events when an item is double-clicked, generate
action events when an item is selected or deselected.
a. List c. Menu item
b. Check box d. Text box
Answer: a
26.Given that a Button can generate an ActionEvent which listener would you
expect to have to implement, in a class which would handle this event?
A. FocusListener. C. WindowListener.
B. ComponentListener. D. ActionListener.
Answer: D
27.Which of the following are valid return types, for listener methods?
A. Boolean. C. Void.
B. the type of event handled. D. Component.
Answer: C
28.Assuming we have a class which implements the ActionListener interface,
which method should beused to register this with a Button?
A. addListener(*); C. addButtonListener(*);
B. addActionListener(*); D. setListener(*);
Answer: B
29.When two or more objects are added as listeners for the same event, which
listener is first invoked tohandle 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
30.Suppose that you want to have an object eh handle the TextEvent of a
TextArea object t. How shouldyou add eh as the event handler for t?
A. t.addTextListener(eh); C. addTextListener(eh.t);
B. eh.addTextListener(t); D. addTextListener(t,eh);
ANSWER: A
31.What is the preferred way to handle an object's events in Java 2?
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: B
32.Which method does display the messages whenever there is an item
selection or deselection of theCheckboxMenuItem menu?
A. itemChanged method. C. itemStateChanged method.
B. itemState method. D. StateChanged method.
Answer: C
33.Adapter classes are used for ...............

A) code redundancy D) none


B) code reduction
C) code organization
Answer: B
34.Which of these methods are used to register a keyboard event listener?
a. KeyListener() c. addKeyListener()
b. addKistener() d. eventKeyboardListener()
Answer: C
35.Which of these methods are used to register a mouse motion listener?
a. addMouse() c. addMouseMotionListner()
b. addMouseListener() d. eventMouseMotionListener()
Answer: C
36.What is a listener in context to event handling?
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
37.Event class is defined in which of these libraries?
a. java.io c. java.net
b. java.lang d. java.util
Answer: d
38.Which of these methods can be used to determine the type of event?
a. getID() c. getEvent()
b. getSource() d. getEventObject()
Answer: a

39.Which of these class is super class of all the events?


a. EventObject c. ActionEvent
b. EventClass d. ItemEvent
Answer: a
40.Which of these events will be notified if scroll bar is manipulated?
a. ActionEvent c. AdjustmentEvent
b. ComponentEvent d. WindowEvent
Answer: c
41.Which of these events will be generated if we close an applet’s window?
a. ActionEvent c. AdjustmentEvent
b. ComponentEvent d. WindowEvent
Answer: d
42.Which of these methods will respond when you click any button by mouse?
a. mouseClicked() c. mousePressed()
b. mouseEntered() d. All of the mentioned
Answer: d
43.Which of these methods will be invoked if a character is entered?
a. keyPressed() c. keyTyped()
b. keyReleased() d. keyEntered()
Answer: c
44.Which of these methods is defined in MouseMotionAdapter class?
a. mouseDragged() c. mouseReleased()
b. mousePressed() d. mouseClicked()
45.Which of these are constants defined in WindowEvent class?
a. WINDOW_ACTIVATED
b. WINDOW_CLOSED
c. WINDOW_DEICONIFIED
d. All of the mentioned
Answer: d
46.The __________ interface is used to handle the menu events
a. ContainerListener c. ActionListener
b. FocusListener d. WindowListener
Answer: c
47.The text field and text area controls create a _________________ area
respectively
a. Single-line text c. Both a & b
b. Multi-line text d. None of these
Answer: c
48.The ___________ interface handles list events:
a. ContainerListener c. ActionListener
b. FocusListener d. ItemListener
Answer: c
49.The ___________ interface handles choice events:
a. ContainerListener c. ActionListener
b. ItemListener d. WindowListener
Answer: b
50.The ___________ interface is used to handle checkbox events:
a. ContainerListener c. ActionListener
b. ItemListener d. WindowListener
Answer: b
51.The ___________ interface is used to handle button events:
a. ContainerListener c. ActionListener
b. ItemListener d. WindowListener
Answer: c

52.Which of these are integer constants defined in ActionEvent class?

a) ALT_MASK d) All of the mentioned


b) CTRL_MASK
c) SHIFT_MASK
Answer: d
53.Which of these methods can be used to know which key is pressed?

a) getKey( ) d) getActionEvent( )
b) getModifier( )
c) getActionKey( )
Answer: b
54.Which of these methods can be used to determine the type of adjustment
event?
a) getType( ) d) getEventObjectType( )
b) getEventType( )
c) getAdjustmentType( )
Answer: c
55.Which of these methods can be used to know the degree of adjustment made
by the user?

a) getValue( ) d) getAdjustmentAmount( )
b) getAdjustmentType( )
c) getAdjustmentValue( )
Answer: a
56.Which of these constant value will change when the button at the end of
scroll bar was clicked to increase its value?

a) BLOCK_DECREMENT d) UNIT_INCREMENT
b) BLOCK_INCREMENT
c) UNIT_DECREMENT
Answer: d
57.Which of these events is generated when the size position an event is
changed?

a) ComponentEvent d) InputEvent
b) ContainerEvent
c) FocusEvent
Answer: a
58.Which of these events is generated when the component is added or
removed?

a) ComponentEvent d) InputEvent
b) ContainerEvent
c) FocusEvent
Answer: b
59.Which of these methods can be used to obtain the reference to the container
that generated
a ContainerEvent? c) getActionEvent( )
a) getContainer( ) d) getContainerEvent )
b) getContainerCommand( )
Answer: d
60.Which of these methods can be used to get reference to a component that
was removed from a container?

a) getComponent( ) d) getComponentChild( )
b) getChild( )
c) getContainerComponent( )
Answer: b
61.Which of these are integer constants of ComponentEvent class?
a) COMPONENT_HIDDEN
b) COMPONENT_MOVED
c) COMPONENT_RESIZE
d) All of the mentioned
ANSWER: d
62.Which of these events is generated when computer gains or losses input
focus?

a) ComponentEvent c) FocusEvent
b) ContainerEvent d) InputEvent
Answer: c
63.FocusEvent is subclass of which of these classes?

a) ComponentEvent d) InputEvent
b) ContainerEvent
c) ItemEvent
Answer: a
64.Which of these methods can be used to know the type of focus change?

a) typeFocus( ) d) isPermanent( )
b) typeEventFocus( )
c) isTemporary( )
Answer: c
65.Which of these is superclass of ContainerEvent class?
a) WindowEvent d) InputEvent
b) ComponentEvent
c) ItemEvent
Answer: b
66.Which of these interfaces define a method actionPerformed( )?

a) ComponentListener d) InputListener
b) ContainerListener
c) ActionListener
Answer: c
67.Which of these interfaces define four methods?

a) ComponentListener d) InputListener
b) ContainerListener
c) ActionListener
Answer: a
68.Which of these methods can be used to obtain the coordinates of a mouse?

a) getPoint( ) d) getMouseCordinates( )
b) getCoordinates( )
c) getMouseXY( )
Answer: a
69.Which of these methods can be used to change location of an event?

a) ChangePoint( ) d) TranslateCordinates( )
b) TranslatePoint( )
c) ChangeCordinates( )
Answer: b
70.Which of these are integer constants of TextEvent class?
a) TEXT_CHANGED
b) TEXT_FORMAT_CHANGED
c) TEXT_VALUE_CHANGED
d) TEXT_sIZE_CHANGED
Answer: b
71.Which of these methods is used to obtain the object that generated a
WindowEvent?

a) getMethod() d) getWindowObject()
b) getWindow()
c) getWindowEvent()
Answer: b
72.Which of these methods is used to get x coordinate of the mouse?

a) getX() d) getPointX()
b) getXCoordinate()
c) getCoordinateX()
Answer: b
73.Which of these is superclass of WindowEvent class?

a) WindowEvent d) InputEvent
b) ComponentEvent
c) ItemEvent
Answer: b
74.Which of the following are true?
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 oits own events.
d) A component may handle its own events only if it implements the
handleEvent( ) method.
Answer: a and b.
75.When two or more objects are added as listeners for the same event, which
listener is 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.

76.Which of the following components generate action events?


a) Buttons c) Check boxes
b) Labels d) Windows
Answer: a.
77.Which of the following are true?
a) A TextField object may generate an ActionEvent.
b) A TextArea object may generate an ActionEvent.
c) A Button object may generate an ActionEvent.
d) A MenuItem object may generate an ActionEvent.
Answer: a,c and d.
78.Which of the following are true?
a) The MouseListener interface defines methods for handling mouse clicks.
b) The MouseMotionListener interface defines methods for handling mouse
clicks.
c) The MouseClickListener interface defines methods for handling mouse
clicks.
d) The ActionListener interface defines methods for handling the clicking of a
button.
Answer: a and d.
79.Which of the following are correct event handling methods
a) mousePressed(MouseEvent e){}
b) MousePressed(MouseClick e){}
c) functionKey(KeyPress k){}
d) componentAdded(ContainerEvent e){}
Answer: a and d.
80.Which of the following are true?
a) A component may have only one event listener attached at a time
b) An event listener may be removed from a component
c) The ActionListener interface has no corresponding Adapter class
d) The processing of an event listener requires a try/catch block
Answer: b and c.
81.Which of these events is generated when the size os an event is changed?

a) ComponentEvent c) FocusEvent
b) ContainerEvent d) InputEvent
Answer: a

82.Which of these events is generated when the a window is closed?

a) TextEvent c) FocusEvent
b) MouseEvent d) WindowEvent
Answer: d
83.Which of these methods can be used to obtain the coordinates of a mouse?
a) getPoint()
b) getCoordinates()
c) getMouseXY()
d) getMouseCordinates()
Answer: a
84.MouseEvent is subclass of which of these classes?

a) ComponentEvent c) ItemEvent
b) ContainerEvent d) InputEvent
Answer: d
85.Which of these packages contains all the event handling interfaces?

a) java.lang c) java.awt.event
b) java.awt d) java.event
Answer: c
86.Which of these interfaces handles the event when a component is added to a
container?

a) ComponentListener c) FocusListener
b) ContainerListener d) InputListener
Answer: b
87.The Following steps are required to perform
1) Implement the Listener interface and overrides its methods
2) Register the component with the Listener
A) Exception Handling
B) String Handling
C) Event Handling
D) None of the above
Answer: C) Event Handling
88.In which places can put the event handling code

A) Same class D) All mentioned above


B) Other class
C) Annonymous class
Answer: D) All mentioned above
89. To use the ActionListener interface it must be implemented by a class
there are 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) All mentioned above
90.The ActionListener interface is used for handling action events,Forexample,it's
used by a

A) JButton
B) JCheckbox
C) JMenuItem
D) All of these
Answer: D) All of these
91. Implement the Listener interface and overrides its methods is required to
perform in event handling?
A) TrueB) False
Answer: A) True
95. Which of these methods can be used to obtain the command name for invoking
ActionEvent object?
a) getCommand()
b) getActionCommand()
c) getActionEvent()
d) getActionEventCommand()

Answer: b

You might also like