0% found this document useful (0 votes)
6 views8 pages

Final MCQ

Uploaded by

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

Final MCQ

Uploaded by

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

Java

1. Which package contains the classes for input


and output in Java?
A) java.util
B) java.lang
C) java.io
D) java.awt

2. What is the default value of a HashMap in


Java?
A) null
B) 0
C) {}
D) []

3. Which method is used to retrieve a value from a


HashMap?
A) getValue()
B) fetch()
C) get()
D) retrieve()
4. Which of the following is NOT a part of the
java.lang package?
A) String
B) System
C) ArrayList
D) Math

5. What is the purpose of the ActionListener


interface?
A) To handle mouse events
B) To handle action button events
C) To manage threads
D) To create GUI components

6. Which method is called when an action event


occurs?
A) actionPerformed()
B) actionEvent()
C) eventOccurred()
D) actionTriggered()

7. Which of the following is used to create a text


area in AWT?
A) TextArea
B) JTextArea
C) TextComponent
D) MultiLineText
8. What is the correct way to declare a HashMap
in Java?
A) HashMap<String, Integer> map = new
HashMap();
B) HashMap map = new HashMap<String,
Integer>();
C) HashMap<String, Integer> map = new
HashMap<String, Integer>();
D) HashMap<String, Integer> map = new
HashMap<>();

9. Which of the following is NOT a valid way to


create a button in Swing?
A) JButton button = new JButton("Click
Me");
B) Button button = new Button("Click Me");
C) JButton button = new JButton();
D) JButton button = new JButton();
button.setText("Click Me");

10. Which method is used to add an


ActionListener to a button in Swing?
A) addListener()
B) addActionListener()
C) registerListener()
D) attachListener()
11. What is the purpose of the java.util
package?
A) To provide classes for GUI components
B) To provide utility classes like collections
and date handling
C) To handle input and output
D) To manage system-level operations

12. Which of the following is a valid way to


create an ArrayList in Java?
A) ArrayList list = new ArrayList();
B) ArrayList<String> list = new
ArrayList<String>();
C) ArrayList<String> list = new
ArrayList<>();
D) All of the above

13. Which method is used to remove an element


from a HashMap?
A) delete()
B) remove()
C) discard()
D) clear()
14. What does the 'main' method in Java
signify?
A) The entry point of any Java application
B) A method that runs in a separate thread
C) A method that handles exceptions
D) A method that creates GUI components

15. Which of the following components is used


to display text in a GUI application?
A) JTextField
B) JLabel
C) JTextArea
D) All of the above

16. Which layout manager is used to arrange


components in a grid?
A) FlowLayout
B) BorderLayout
C) GridLayout
D) BoxLayout

17. What method is used to set the size of a


JFrame?
A) setDimensions()
B) setSize()
C) resize()
D) setFrameSize()
18. Which of the following is NOT a type of
layout manager in AWT?
A) FlowLayout
B) GridBagLayout
C) CardLayout
D) StackLayout

19. What does the 'final' keyword signify when


applied to a variable?
A) The variable can be changed
B) The variable cannot be changed
C) The variable is a constant
D) Both B and C

20. Which method is called to make a JFrame


visible?
A) show()
B) display()
C) setVisible(true)
D) open()
ANSWER

1. Answer: C) java.io
2. Answer: C) {}
3. Answer: C) get()
4. Answer: C) ArrayList
5. Answer: B) To handle action button events
6. Answer: A) actionPerformed()
7. Answer: A) TextArea
8. Answer: D) HashMap<String, Integer> map = new
HashMap<>();
9. Answer: B) Button button = new Button("Click
Me");
10. Answer: B) addActionListener()
11. Answer: B) To provide utility classes like
collections and date handling
12. Answer: D) All of the above
13. Answer: B) remove()
14. Answer: A) The entry point of any Java
application
15. Answer: D) All of the above
16. Answer: C) GridLayout
17. Answer: B) setSize()
18. Answer: D) StackLayout
19. Answer: D) Both B and C
20. Answer: C) setVisible(true)

You might also like