Java MCQ – Event Handling

This section of our 1000+ Java MCQs focuses on event handling in Java Programming Language.

1. 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
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?
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.

3. 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.
advertisement
advertisement

4. Which of these methods are used to register a mouse motion listener?
a) addMouse()
b) addMouseListener()
c) addMouseMotionListner()
d) eventMouseMotionListener()
View Answer

Answer: c
Explanation: None.

5. 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
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.
Note: Join free Sanfoundry classes at Telegram or Youtube

6. Event class is defined in which of these libraries?
a) java.io
b) java.lang
c) java.net
d) java.awt.event
View Answer

Answer: d
Explanation: The Event class is part of the java.awt.event package, which provides various event classes for handling events in Java. Even though the Event class exists in Java, it is considered obsolete as of Java 1.1 due to the introduction of more specific and efficient event handling mechanisms.

7. 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
Explanation: getID() can be used to determine the type of an event.
advertisement

8. 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.

9. 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.
advertisement

10. 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.

Sanfoundry Global Education & Learning Series – Java Programming Language.

If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.