Chapter No.
2 Event Handling
Multiple choice Question
2.1 The delegation Event Model
1) What is an event in delegation event model used by Java programming language?
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.
View Answer
Answer: a
2) Event class is defined in which of these libraries?
a) java.io
b) java.lang
c) java.net
d) java.util
View Answer
Answer: d
3) Which of these methods can be used to determine the type of event?
a) getID()
b) getSource()
c) getEvent()
d) getEventObject()
View Answer
Answer: a
4) Which of these class is super class of all the events?
a) EventObject
b) EventClass
c) ActionEvent
d) ItemEvent
View Answer
Answer: a
Explanation: EventObject class is a super class of all the events and is defined in java.util
package.
5) Which of these events will be notified if scroll bar is manipulated?
a) ActionEvent
b) ComponentEvent
c) AdjustmentEvent
d) WindowEvent
View Answer
Answer: c
Explanation: AdjustmentEvent is generated when a scroll bar is manipulated.
6) Which of these events will be generated if we close an applet’s window?
a) ActionEvent
b) ComponentEvent
c) AdjustmentEvent
d) WindowEvent
View Answer
Answer: d
Explanation: WindowEvent is generated when a window is activated, closed, deactivated,
deiconfied, iconfied, opened or quit.
7) Which of these events is generated when a button is pressed?
a) ActionEvent
b) KeyEvent
c) WindowEvent
d) AdjustmentEvent
View Answer
Answer: a
Explanation: Action event is generated when a button is pressed, a list item is double-clicked
or a menu item is selected.
8) What is an event in delegation event model used by Java programming language?
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.
View Answer
Answer: a
Explanation: An event is an object that describes a state change in a source.
9) Which of these methods can be used to obtain the command name for invoking
ActionEvent object?
a) getCommand()
b) getActionCommand()
c) getActionEvent()
d) getActionEventCommand()
View Answer
Answer: b
10) 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
11)Where can the event handling code be written?
a. Same class
b. Other class
c. Anonymous class
d. All mentioned above
ANSWER: All mentioned above
12) The ActionListener interface is not used for handling action events?
[A] True
[B] False
Answer: B. False
13) The ActionListener interface is used for handling action events, For example,it's
used by a
[A] JButton
[B] JCheckbox
[C] JMenuItem
[D] All of these
Answer: D. All of these
14) Which class is used for this Processing Method processActionEvent( )?
a. Button,List,MenuItem
b. Button,Checkbox,Choice
c. Scrollbar,Component,Button
d. None of the above
ANSWER: Button,List,MenuItem
15)The ActionListener interface is not used for handling
action events
a. True
b. False
ANSWER: False
16)Which of these packages contains all the classes and methods required for even
handling in Java?
a) java.applet
b) java.awt
c) java.event
d) java.awt.event
View Answer
Answer: d
2.2 Adapter Classes
1)Which Adaptors are in Java?
a) interface
b) class
c) Subclass
d) java.awt.event
View Answer
Answer: b
2)Which MouseListener implemented by which class in Java?
b) KeyAdaptor
c) AdjustmentAdaptor
d) MouseMotionAdaptor
View Answer
Answer: a
3)Which AdjustmentListener implemented by which class in Java?
a) MouseAdaptor
b) KeyAdaptor
c) AdjustmentAdaptor
d) MouseMotionAdaptor
View Answer
Answer: c
4)Which KeyListener implemented by which class in Java?
a) MouseAdaptor
b) KeyAdaptor
c) AdjustmentAdaptor
d) MouseMotionAdaptor
View Answer
Answer: b
5)Which MouseMotionListener implemented by which class in Java?
a) MouseAdaptor
b) KeyAdaptor
c) AdjustmentAdaptor
d) MouseMotionAdaptor
View Answer
Answer: d
6)Which MouseEntered()defined by which class in Java?
a) MouseAdaptor
b) KeyAdaptor
c) AdjustmentAdaptor
d) MouseMotionAdaptor
View Answer
Answer: a
7)Which ItemStateChanged() method defined by which class in Java?
a) MouseAdaptor
b) ItemAdaptor
c) AdjustmentAdaptor
d) MouseMotionAdaptor
View Answer
Answer: b
8)Which actionPerformed() implemented by which class in Java?
a) ActionListener
b) KeyAdaptor
c) AdjustmentAdaptor
d) MouseMotionAdaptor
View Answer
Answer: a
9)Which is the container that contain title bar and can have MenuBars. It can have
other components like button, textfield etc.?
[A] Panel
[B] Frame
[C] Window
[D] Container
Answer: B. Frame
Explanation: A Frame is a top-level window with a title and a border. The size of the frame
includes any area designated for the border
2.3 Event Listener Interfaces
1) Which of these methods are used to register a keyboard event listener?
a) KeyListener()
b) addKistener()
c) addKeyListener()
d) eventKeyboardListener()
View Answer
Answer: c
Explanation: None
2)Which of these methods are used to register a mouse motion listener?
a) addMouse()
b) addMouseListener()
c) addMouseMotionListner()
d) eventMouseMotionListener()
View Answer
Answer: c
3) 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
View Answer
Answer: b
4)Implement the Listener interface and overrides its methods is required to perform in
event handling.
a. True
b. False
ANSWER: True
5) The ActionListener interface is not used for handling action events.
a. True
b. False
ANSWER: False
6)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
Explanation: it is used by all the class.
7)Which package provides many event classes and Listener interfaces for event
handling?
a. java.awt
b. java.awt.Graphics
c. java.awt.event
d. None of the above
ANSWER: java.awt.event
8)Which of these are integer constants defined in ActionEvent class?
a) ALT_MASK
b) CTRL_MASK
c) SHIFT_MASK
d) All of the mentioned
View Answer
Answer: d
Explanation: Action event defines 4 integer constants ALT_MASK, CTRL_MASK, SHIFT_MASK and
ACTION_PERFORMED
9) Which of these methods can be used to know which key is pressed?
a) getKey()
b) getModifier()
c) getActionKey()
d) getActionEvent()
View Answer
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.
10) Which of these events is generated by scroll bar?
a) ActionEvent
b) KeyEvent
c) WindowEvent
d) AdjustmentEvent
View Answer
Answer: d
Explanation: None.
11) Which of these methods can be used to determine the type of adjustment event?
a) getType()
b) getEventType()
c) getAdjustmentType()
d) getEventObjectType()
View Answer
Answer: c
Explanation: None.
12) Which of these methods can be used to know the degree of adjustment made by the user?
a) getValue()
b) getAdjustmentType()
c) getAdjustmentValue()
d) getAdjustmentAmount()
View Answer
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.
13) Which of these events will be notified if scroll bar is manipulated?
a) ActionEvent
b) ComponentEvent
c) AdjustmentEvent
d) WindowEvent
View Answer
Answer: c
Explanation: AdjustmentEvent is generated when a scroll bar is manipulated.
14) 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
b) BLOCK_INCREMENT
c) UNIT_DECREMENT
d) UNIT_INCREMENT
View Answer
Answer: d
Explanation: UNIT_INCREMENT VALUE will change when the button at the end of scroll bar was
clicked to increase its value.
15) Which of these events is generated when the size os an event is changed?
a) ComponentEvent
b) ContainerEvent
c) FocusEvent
d) InputEvent
View Answer
Answer: a
Explanation: A ComponentEvent is generated when the size, position or visibility of a component is
changed.
16) Which of these events is generated when the component is added or removed?
a) ComponentEvent
b) ContainerEvent
c) FocusEvent
d) InputEvent
View Answer
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.
17) Which of these methods can be used to obtain the reference to the container that generated a
ContainerEvent?
a) getContainer()
b) getContainerCommand()
c) getActionEvent()
d) getContainerEvent()
View Answer
Answer: d
Explanation: None.
18) Which of these methods can be used to get reference to a component that was removed from a
container?
a) getComponent()
b) getchild()
c) getContainerComponent()
d) getComponentChild()
View Answer
Answer: b
Explanation: The getChild() method returns a reference to the component that was added to or removed
from the container.
19) Which of these are integer constants of ComponentEvent class?
a) COMPONENT_HIDDEN
b) COMPONENT_MOVED
c) COMPONENT_RESIZE
d) All of the mentioned
View Answer
Answer: d
Explanation: The component event class defines 4 constants COMPONENT_HIDDEN, COMPONENT-
MOVED, COMPONENT-RESIZE and COMPONENT-SHOWN.
20) Which of these events is generated when computer gains or losses input focus?
a) ComponentEvent
b) ContainerEvent
c) FocusEvent
d) InputEvent
View Answer
Answer: c
Explanation: None.
21) FocusEvent is subclass of which of these classes?
a) ComponentEvent
b) ContainerEvent
c) ItemEvent
d) InputEvent
View Answer
Answer: a
Explanation: None.
22) Which of these methods can be used to know the type of focus change?
a) typeFocus()
b) typeEventFocus()
c) isTemporary()
d) isPermanent()
View Answer
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.
23) Which of these events will be notified if scroll bar is manipulated?
a) ActionEvent
b) ComponentEvent
c) AdjustmentEvent
d) WindowEvent
View Answer
Answer: c
Explanation: AdjustmentEvent is generated when a scroll bar is manipulated.
24) Which of these is superclass of ContainerEvent class?
a) WindowEvent
b) ComponentEvent
c) ItemEvent
d) InputEvent
View Answer
Answer: b
Explanation: ContainerEvent is superclass of ContainerEvent, FocusEvent, KeyEvent, MouseEvent and
WindowEvent.
25) Which of these events is generated when the a window is closed?
a) TextEvent
b) MouseEvent
c) FocusEvent
d) WindowEvent
View Answer
Answer: d
Explanation: A WindowEvent is generated when a window is opened, close, activated or deactivated.
26) Which of these events is generated when the component is added or removed?
a) ComponentEvent
b) ContainerEvent
c) FocusEvent
d) InputEvent
View Answer
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.
27) Which of these methods can be used to obtain the coordinates of a mouse?
a) getPoint()
b) getCoordinates()
c) getMouseXY()
d) getMouseCordinates()
View Answer
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?
a) ChangePoint()
b) TranslatePoint()
c) ChangeCordinates()
d) TranslateCordinates()
View Answer
Answer: b
Explanation: None.
29) Which of these are integer constants of TextEvent class?
a) TEXT_CHANGED
b) TEXT_FORMAT_CHANGED
c) TEXT_VALUE_CHANGED
d) TEXT_sIZE_CHANGED
View Answer
Answer: b
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?
a) getMethod()
b) getWindow()
c) getWindowEvent()
d) getWindowObject()
View Answer
Answer: b
Explanation: None.
31) MouseEvent is subclass of which of these classes?
a) ComponentEvent
b) ContainerEvent
c) ItemEvent
d) InputEvent
View Answer
Answer: d
Explanation: None.
32) Which of these methods is used to get x coordinate of the mouse?
a) getX()
b) getXCoordinate()
c) getCoordinateX()
d) getPointX()
View Answer
Answer: b
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?
a) WINDOW_ACTIVATED
b) WINDOW_CLOSED
c) WINDOW_DEICONIFIED
d) All of the mentioned
View Answer
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?
a) WindowEvent
b) ComponentEvent
c) ItemEvent
d) InputEvent
View Answer
Answer: b
Explanation: ContainerEvent is superclass of ContainerEvent, FocusEvent, KeyEvent, MouseEvent and
WindowEvent.
2.4 Inner Classes
Q 1. Which is true about an anonymous inner class?
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: Option C
Q 2. class Boo
{
Boo(String s) { }
Boo() { }
}
class Bar extends Boo
{
Bar() { }
Bar(String s) {super(s);}
void zoo()
{
// insert code here
}
}
which one create an anonymous inner class from within class Bar?
A
Boo f = new Boo(24) { };
.
B
Boo f = new Bar() { };
.
C
Bar f = new Boo(String s) { };
.
D
Boo f = new Boo.Bar(String s) { };
.
Answer: Option B
Q 3.Which is true about a method-local inner class?
A
It must be marked final.
.
B
It can be marked abstract.
.
C
It can be marked public.
.
D
It can be marked static.
.
Q 4.Which statement is true about a static nested class?
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: Option B
Q 5.Which constructs an anonymous inner class instance?
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: Option D
Q 6.
class Foo
{
class Bar{ }
}
class Test
{
public static void main (String [] args)
{
Foo f = new Foo();
/* Line 10: Missing statement ? */
}
}
which statement, inserted at line 10, creates an instance of Bar?
A
Foo.Bar b = new Foo.Bar();
.
B
Foo.Bar b = f.new Bar();
.
C
Bar b = new f.Bar();
.
D
Bar b = f.new Bar();
.
Answer : Option B
Q 7.
public class MyOuter
{
public static class MyInner
{
public static void foo() { }
}
}
which statement, if placed in a class other than MyOuter or MyInner, instantiates an instance of the
nested class?
A
MyOuter.MyInner m = new MyOuter.MyInner();
.
B
MyOuter.MyInner mi = new MyInner();
.
MyOuter m = new MyOuter();
C
. MyOuter.MyInner mi = m.new MyOuter.MyInner();
D
MyInner mi = new MyOuter.MyInner();
.
Answer: Option A
tbj3$IS5