Unit 2 MCQ BY ROOMIES
Unit 2 MCQ BY ROOMIES
Unit 2 :
2. Which of these packages contains all the classes and methods required for event handling in
Java?
- A) java.awt
- B) java.util
- C) java.event
- D) java.awt.event
- Answer: D) java.awt.event
5. Which of these methods can be used to know the degree of adjustment made by the user?
- A) getAdjustment()
- B) calculateAdjustment()
- C) getValue()
- D) adjustValue()
- Answer: C) getValue()
7. A source generates an event and sends it to ___________ listeners that can handle the event.
- A) Only one
- B) At least two
- C) One or more
- D) Exactly three
- Answer: C) One or more
- C) AddRemoveEvent
- D) ChangeEvent
- Answer: B) ContainerEvent
13. An event is generated when the internal state of the event source is ___________.
- A) Constant
- B) Initialized
- C) Changed
- D) Reset
- Answer: C) Changed
UNIT 2 MCQ BY ROOMIES
15. At the root of the Java event class hierarchy is ___________ which is the superclass for all
events.
- A) EventRoot
- B) EventBase
- C) EventSource
- D) EventObject
- Answer: D) EventObject
- A) Only ActionEvent
- B) Only WindowEvent
- C) Only AdjustmentEvent
- D) All of the above
- Answer: D) All of the above
- C) FrameEvent
- D) SystemEvent
- Answer: A) WindowEvent
- D) 5
- Answer: C) 4
33. If a class extends the ActionListener interface, it must contain a method called. __________.
- A) action()
- B) actionPerformed()
- C) execute()
- D) handleAction()
- Answer: B) actionPerformed()
- D) ScrollBarEvent
- Answer: C) AdjustmentEvent
38. In Java, an event is an _________ which specifies the change of state in the source.
- A) Abstract
- B) Object
- C) Entity
- D) Indicator
UNIT 2 MCQ BY ROOMIES
- Answer: B) Object
39. In Java, events are all the activities that occur between ___________.
- A) A and C
- B) A and B
- C) B and D
- D) C and D
- Answer: B) A and B
41. In which package the methods for receiving and processing events are defined?
- A) java.util
- B) javax.event
- C) java.awt
- D) java.awt.event
- Answer: D) java.awt.event
49. Name the event that gets generated when a button is clicked.
- A) ButtonEvent
- B) ClickEvent
- C) ActionEvent
- D) PressEvent
- Answer: C) ActionEvent
50. Name the method defined in EventObject class that returns the Object generated from the
event. Select the one correct answer.
- A) getObject()
- B) getEventSource()
- C) getSourceObject()
- D) getSource()
- Answer: D) getSource()
UNIT 2 MCQ BY ROOMIES
- A) keyPressed(KeyEvent e)
- B) keyReleased(KeyEvent e)
- C) keyTyped(KeyEvent e)
- D) All of the mentioned
- Answer: D) All of the mentioned
68. The method in the ActionEvent ________ returns the action command of the button.
- A) getAction()
- B) fetchAction()
- C) getCommand()
- D) getActionCommand()
- Answer: D) getActionCommand()
69. The method that is used for registering a keyboard event is known as
____________________.
- A) registerKeyListener()
- B) addKeyListener()
- C) attachKeyListener()
- D) setKeyListener()
- Answer: B) addKeyListener()
70. The MouseEvent class does not define the _____________ integer constant.
- A) MOUSE_WHEELMOVE
- B) MOUSE_DRAGGED
- C) MOUSE_MOVED
- D) MOUSE_PRESSED
- Answer: A) MOUSE_WHEELMOVE
UNIT 2 MCQ BY ROOMIES
72. The MouseListener's _______________ method is called after the mouse button is released.
- A) public void mouseUp(MouseEvent e)
- B) public void mouseReleased(MouseEvent e)
- C) public void mouseClicked(MouseEvent e)
- D) public void mousePressed(MouseEvent e)
- Answer: B) public void mouseReleased(MouseEvent e)
74. The signature for the registration method for an ActionEvent should be.
- A) public void addActionListener(ActionListener l)
- B) public void registerActionListener(ActionListener l)
- C) public void addEventActionListener(ActionListener l)
- D) public void attachActionListener(ActionListener l)
- Answer: A) public void addActionListener(ActionListener l)
- A) ComponentEvent
- B) AWTEvent
- C) EventObject
- D) InputEvent
- Answer: B) AWTEvent
79. Till now two models have been introduced in java for:
UNIT 2 MCQ BY ROOMIES
- A) Event Handling
- B) Receiving and processing events
- C) Event Delegation
- D) Both A and B
- Answer: D) Both A and B
86. What kind of event is fired when the user selects an item from a menu?
- A) MenuEvent
- B) ItemEvent
- C) ActionEvent
- D) SelectEvent
- Answer: C) ActionEvent
- A) ResizeEvent
- B) SizeChangeEvent
- C) ComponentChangeEvent
- D) ComponentEvent
- Answer: D) ComponentEvent
92. 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 listener added
- B) The last listener added
- C) There is no way to determine which listener will be invoked first.
- D) All listeners are invoked simultaneously.
- Answer: C) There is no way to determine which listener will be invoked first.
93. When we need to use checkboxes or items from the list or use a checkable menu, an
________________ is generated.
- A) CheckEvent
- B) ItemEvent
- C) CheckboxEvent
- D) SelectEvent
- Answer: B) ItemEvent
- D) ContainerEvent
- Answer: C) AdjustEvent
97. Which are various methods of WindowListener interface from the following?
- A) void windowOpened(WindowEvent e)
- B) void windowClosing(WindowEvent e)
- C) void windowActivated(WindowEvent e)
- D) All of the above
- Answer: D) All of the above
99. Which class is at the root in the Java event class hierarchy?
- A) EventClass
- B) EventObject
- C) EventSource
- D) RootEvent
- Answer: B) EventObject
UNIT 2 MCQ BY ROOMIES
107. Which method does display the message whenever there is an item selection or deselection
of the CheckboxMenuItem menu?
- A) itemSelected()
- B) itemChanged()
- C) itemStateChanged method.
- D) itemClicked()
- Answer: C) itemStateChanged method.
UNIT 2 MCQ BY ROOMIES
118. Which of the following is the highest class in the event delegation class hierarchy?
- A) java.util.EventObject
- B) java.awt.event.Event
- C) java.awt.event.DelegateEvent
- D) java.awt.event.HighestEvent
- Answer: A) java.util.EventObject
A) ActionEvent
- B) ButtonEvent
- C) ClickEvent
- D) PressEvent
- Answer: A) ActionEvent
123. Which of these methods can be used to obtain the command name for invoking
ActionEvent object?
- A) getActionCommand()
- B) retrieveCommand()
- C) fetchActionCommand()
UNIT 2 MCQ BY ROOMIES
- D) obtainCommandName()
- Answer: A) getActionCommand()
127. Which of these constant values will change when the button at the end of the scrollbar is
clicked to increase its value?
- A) UNIT_DECREMENT
- B) UNIT_INCREMENT
- C) BLOCK_DECREMENT
UNIT 2 MCQ BY ROOMIES
- D) BLOCK_INCREMENT
- Answer: B) UNIT_INCREMENT
128. Which of these events is generated when the computer gains or loses input focus?
- A) FocusEvent
- B) InputFocusEvent
- C) WindowEvent
- D) KeyEvent
- Answer: A) FocusEvent
131. Which of these events is generated when the component is added or removed?
- A) ContainerEvent
- B) AddRemoveEvent
- C) ComponentChangeEvent
- D) ComponentEvent
UNIT 2 MCQ BY ROOMIES
- Answer: A) ContainerEvent
- Answer: C) Adapter
136. Which of these methods are used to determine the type of adjustment event?
- A) getAdjustmentType()
- B) determineAdjustmentType()
- C) fetchAdjustmentType()
- D) obtainAdjustmentType()
- Answer: A) getAdjustmentType()
137. Which of these methods are used to register a mouse motion listener?
- A) addMouseListener()
- B) addMouseMotionListener()
- C) registerMouseMotionListener()
- D) attachMouseMotionListener()
- Answer: B) addMouseMotionListener()
138. Which of these methods can be used to know the degree of adjustment made by the user?
- A) getDegree()
- B) fetchAdjustment()
- C) determineAdjustment()
- D) getValue()
- Answer: D) getValue()
- Answer: B) mouseDragged()
140. Which of these methods is used to get the x-coordinate of the mouse?
- A) getX()
- B) fetchX()
- C) obtainX()
- D) determineX()
- Answer: A) getX()
142. Which of these methods is used to know the full URL of a URL object?
- A) getFullURL()
- B) fetchURL()
- C) determineURL()
- D) getHost()
- Answer: D) getHost()
143. Which of these methods is used to obtain the object that generated a ComponentEvent?
- A) getComponent()
- B) fetchObject()
- C) determineObject()
- D) getContainer()
UNIT 2 MCQ BY ROOMIES
- Answer: D) getContainer()
144. Which of these methods is used to obtain the object that generated a WindowEvent?
- A) getWindowObject()
- B) fetchWindowObject()
- C) determineWindowObject()
- D) getWindow()
- Answer: D) getWindow()
146. Which of these methods will respond when you click any button by mouse?
- A) mouseClicked()
- B) buttonClicked()
- C) actionPerformed()
- D) All of the mentioned
- Answer: D) All of the mentioned
147. Which of these methods will respond when you click any button by mouse?
- A) mouseClicked()
- B) buttonClicked()
- C) actionPerformed()
- D) All of these
UNIT 2 MCQ BY ROOMIES
- Answer: C) actionPerformed()
149. Which two parameters are required for JTable constructor to create a table?
- A) Data array and Column Headings
- B) Rows and Columns
- C) Table size and Color
- D) Data array and Table size
- Answer: A) Data array and Column Headings
- Answer: A) List
152. __________ is generated when a checkbox is clicked, a list item is clicked, a choice selection
is made, or a checkable menu item is selected or deselected.
- A) MouseEvent
- B) ItemEvent
- C) ActionEvent
- D) CheckboxEvent
- Answer: B) ItemEvent
153. ___________ class provides an empty implementation of all methods in an Event Listener
interface?
- A) Adapter
- B) EmptyListener
- C) AbstractListener
- D) NullListener
- Answer: A) Adapter
156. For the following code, select the method that can be used to handle the event.
```java
import java.awt.event.;
import java.awt.;
import java.applet.;
}
/<applet code=checkbackg.class height=150 width=150> </applet>/
```
- A) itemStateChanged(ItemEvent ie)
- B) itemChanged(ItemEvent ie)
- C) itemSelected(ItemEvent ie)
- D) itemClicked(ItemEvent ie)
- Answer: A) itemStateChanged(ItemEvent ie)
157. For Key events, KeyEvent class is used 2) For Mouse motion events, MouseEvent class is
used 3) For Component events, ComponentEvent class is used 4) For Window events,
WindowEvent class is used
- A) 1, 2, 3 are true
- B) 1, 2, 4 are true
- C) 2, 3, 4 are true
- D) 1, 3, 4 are true
- Answer: D) 1, 3, 4 are true
}
}
public mma1(adm a) {
this.a = a;
}
159. Which line of code is missing in the following code, and what is the error statement?
```java
import java.awt.;
import java.awt.event.;
import java.applet.;
160. What will happen when you attempt to compile and run the following code?
```java
import java.awt.;
import java.awt.event.;
UNIT 2 MCQ BY ROOMIES
MClick() {
this.addMouseListener(this);
}
c.setLayout(new FlowLayout());
162. A Frame's background color is set to Color.Yellow, and a Button's background color is set
to Color.Blue. Suppose the Button is added to a Panel, which is added to the Frame. What
background color will be used with the Panel?
- A) Color.Blue
- B) Color.Yellow
- C) Color.Green
- D) Color.Red
- Answer: B) Color.Yellow
- Answer: A) True
```java
import java.awt.;
import java.awt.event.;
import java.applet.;
Options:
1. `Button no=new Button("NO");`
2. `Button undecided=new Button("Undecided");`
3. `Button maybe=new Button("Maybe");`
4. `Button no=new Button("No");`
---
168: After inserting which statement in the following program, the output window will be
closed when the close button is clicked?
```java
import java.awt.event.;
import java.awt.;
setTitle("My Window");
}
AdapterDemo(Demo d) {
d1=d;
}
public void windowClosing(WindowEvent we) {
d1.dispose();
}
}
```
Options:
1. `addWindowListener(new AdapterDemo(this));`
2. `this.addWindowListener(new AdapterDemo(this));`
3. `AdapterDemo ad = new AdapterDemo(this);`
4. `new AdapterDemo(this).addWindowListener();`
---
Options:
1. `MouseListener`
UNIT 2 MCQ BY ROOMIES
---
170:An event is generated when the internal state of the event source is __________.
Options:
1. `stopped`
2. `changed`
3. `initialized`
4. `paused`
Answer: 2. `changed`
---
---
173:Analyse the following code and find out the missing statement:
```java
import java.awt.;
import java.applet.;
UNIT 2 MCQ BY ROOMIES
Options:
1. `TextField jtf=new TextField(12);`
2. `TextField jtf;`
3. `TextField jtf=new TextField();`
4. `All of the above`
---
UNIT 2 MCQ BY ROOMIES
```java
import javax.swing.;
import javax.swing.border.;
import java.awt.;
Options:
1. `Two buttons displayed with the same border.`
2. `Two buttons displayed with different borders.`
3. `No buttons displayed.`
UNIT 2 MCQ BY ROOMIES
```java
import javax.swing.;
import java.awt.;
JButton("Java"));
add(new JButton("Java"));
add(new JButton("Java"));
add(new JButton("Java"));
}
Options:
1. `Four buttons are displayed with the same text "Java".`
UNIT 2 MCQ BY ROOMIES
Answer: 1. `Four buttons are displayed with the same text "Java".`
---
Options:
1. `CheckBox`
2. `RadioButton`
3. `ToggleButton`
4. `ComboBox`
Answer: 2. `RadioButton`
177: Choose the correct missing statement from the given code:
```java
import java.awt.;
import java.applet.;
import java.awt.event.;
b1 = new Button("FACTORIAL");
add(t1);
add(t2);
add(b1);
}
Options:
1. `b1.addActionListener(this);`
2. `t1.addActionListener(this);`
3. `b1.addMouseListener(this);`
4. `t2.addActionListener(this);`
Answer: 1. `b1.addActionListener(this);`
---
```java
import java.awt.;
import java.awt.event.;
import java.applet.;
Options:
1. The program will display "Button clicked" message in the status bar on clicking the button with the
mouse.
2. The program will display "Mouse clicked" message in the status bar on clicking the button with the
mouse.
3. The program will display "Button pressed" message in the status bar on pressing the button.
4. The program will not display any message.
Answer: 1. The program will display "Button clicked" message in the status bar on clicking the
button with the mouse.
---
```java
/ <applet code="MyControl10" width=300 height=300> </applet> /
import java.applet.;
import java.awt.;
import java.awt.event.;
Options:
1. All of the above
2. Only "Red" checkbox selected will fill the rectangle with red color.
3. Only "Green" checkbox selected will fill the rectangle with green color.
4. Only "Blue" checkbox selected will fill the rectangle with blue color.
Answer: 2. Only "Red" checkbox selected will fill the rectangle with red color.
---
59 | P a g e
180: Choose the correct output from the following options when the key is pressed.
```java
/ <applet code="SimpleKey" width=300 height=100> </applet> /
import java.awt.;
UNIT 2 MCQ BY ROOMIES
import java.awt.event.;
import java.applet.;
Options:
1. Key Down msg shown at the status bar
UNIT 2 MCQ BY ROOMIES