[go: up one dir, main page]

0% found this document useful (0 votes)
16 views5 pages

Java MCQ Questions

The document contains 100 multiple choice questions (MCQs) related to Java programming, covering topics such as Java basics, data types, operators, control structures, object-oriented programming, exception handling, arrays, file I/O, multithreading, GUI, and advanced concepts. Each question is accompanied by four answer options and the correct answer is provided. The document serves as a comprehensive review tool for students studying Java programming.

Uploaded by

munalroyal2
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)
16 views5 pages

Java MCQ Questions

The document contains 100 multiple choice questions (MCQs) related to Java programming, covering topics such as Java basics, data types, operators, control structures, object-oriented programming, exception handling, arrays, file I/O, multithreading, GUI, and advanced concepts. Each question is accompanied by four answer options and the correct answer is provided. The document serves as a comprehensive review tool for students studying Java programming.

Uploaded by

munalroyal2
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/ 5

100 Multiple Choice Questions (MCQs) with Answers: COS202 - Java Programming

Java Basics

1–10 [Already listed above]

Data Types and Variables

11–20 [Already listed above]

Operators and Expressions

21–30 [Already listed above]

Control Structures and Loops

31–40 [Already listed above]

Object-Oriented Programming

41. What is the default access modifier in Java?\ a) public\ b) private\ c) protected\ d) package-
private\ Answer: d

42. Which keyword is used to create a class object?\ a) class\ b) object\ c) new\ d) this\ Answer: c

43. Which keyword refers to the current object?\ a) this\ b) super\ c) current\ d) self\ Answer: a

44. What is method overloading?\ a) Defining multiple methods with same name but different
parameters\ b) Writing multiple classes\ c) Calling one method from another\ d) Using inheritance\
Answer: a

45. Which keyword is used to inherit a class?\ a) implement\ b) inherits\ c) super\ d) extends\
Answer: d

46. A class can extend:\ a) One class only\ b) Two classes\ c) Multiple classes\ d) No class\ Answer: a

47. Which of the following is true about constructors?\ a) Must have return type\ b) Must match class
name\ c) Must be static\ d) Can be abstract\ Answer: b

48. What is encapsulation?\ a) Hiding implementation details\ b) Inheriting methods\ c) Creating


subclasses\ d) Sharing code between objects\ Answer: a

1
49. Interface methods are by default:\ a) private\ b) public and abstract\ c) protected\ d) static\
Answer: b

50. Can a class implement multiple interfaces?\ a) No\ b) Only one\ c) Yes\ d) Only abstract classes\
Answer: c

Exception Handling

51. What keyword is used to handle exceptions?\ a) try\ b) catch\ c) throw\ d) All of the above\
Answer: d

52. Which class is the superclass of all exceptions?\ a) Object\ b) Throwable\ c) Runtime\ d) Exception\
Answer: b

53. Which block is always executed?\ a) try\ b) catch\ c) throw\ d) finally\ Answer: d

54. What is the use of ** throw **?\ a) To declare an exception\ b) To catch an exception\ c) To throw
an exception\ d) To ignore exceptions\ Answer: c

55. Which keyword is used to define a method may throw exception?\ a) catch\ b) throws\ c) try\ d)
handle\ Answer: b

Arrays and Strings

56. How do you declare an array in Java?\ a) int arr[];\ b) int[] arr;\ c) both a and b\ d) None of the
above\ Answer: c

57. What is the index of the first element in an array?\ a) -1\ b) 0\ c) 1\ d) Depends\ Answer: b

58. Which class is used to manipulate strings?\ a) Text\ b) String\ c) Array\ d) Character\ Answer: b

59. Strings in Java are:\ a) Mutable\ b) Immutable\ c) Static\ d) Changeable\ Answer: b

60. Which method compares two strings?\ a) equals()\ b) ==\ c) compareTo()\ d) Both a and c\ Answer:
d

File I/O and Packages

61. Which class is used to read a file?\ a) FileWriter\ b) FileReader\ c) Scanner\ d) All of the above\
Answer: d

62. What does the ** import ** keyword do?\ a) Create packages\ b) Load class libraries\ c) Read
input\ d) Export files\ Answer: b

63. Which package contains Scanner class?\ a) java.util\ b) java.io\ c) java.lang\ d) java.text\ Answer: a

2
64. To write to a file in Java, you can use:\ a) PrintWriter\ b) FileWriter\ c) BufferedWriter\ d) All of the
above\ Answer: d

65. What does ** File.exists() ** return?\ a) Integer\ b) Boolean\ c) String\ d) File object\ Answer:
b

Multithreading and Concurrency

66. Which keyword is used to create a thread?\ a) thread\ b) Thread\ c) implements Runnable\ d) Both
b and c\ Answer: d

67. What is the method to start a thread?\ a) begin()\ b) start()\ c) init()\ d) run()\ Answer: b

68. Which interface must be implemented for multithreading?\ a) Threadable\ b) Runnable\ c)


Startable\ d) None\ Answer: b

69. Which method is used to delay execution?\ a) stop()\ b) sleep()\ c) wait()\ d) pause()\ Answer: b

70. Threads in Java belong to which package?\ a) java.io\ b) java.net\ c) java.util\ d) java.lang\ Answer:
d

GUI and Java APIs

71. Which package is used for GUI in Java?\ a) java.awt\ b) javax.swing\ c) Both a and b\ d) java.gui\
Answer: c

72. What is a JFrame?\ a) A type of class\ b) A top-level window\ c) A Java interface\ d) None\ Answer: b

73. Which component is used to take text input in Swing?\ a) JTextArea\ b) JLabel\ c) JTextField\ d)
JEditor\ Answer: c

74. Which method sets the size of a frame?\ a) setWidth()\ b) setSize()\ c) setLength()\ d) setBounds()\
Answer: b

75. Which layout arranges components in flow?\ a) BorderLayout\ b) GridLayout\ c) FlowLayout\ d)


CardLayout\ Answer: c

Advanced Concepts

76. What is polymorphism?\ a) Multiple constructors\ b) Overriding and overloading\ c) Inheritance\ d)


Typecasting\ Answer: b

77. Which of the following is not a primitive type?\ a) int\ b) float\ c) boolean\ d) String\ Answer: d

78. Which statement is true about Java?\ a) Java supports pointers\ b) Java is platform-independent\
c) Java does not support inheritance\ d) Java is purely procedural\ Answer: b

3
79. Which keyword prevents method overriding?\ a) private\ b) static\ c) final\ d) public\ Answer: c

80. Which of these can be declared abstract?\ a) Method\ b) Class\ c) Both\ d) Interface\ Answer: c

Mixed Review (81–100)

81. Which access modifier gives least access?\ a) public\ b) protected\ c) default\ d) private\ Answer:
d

82. The ** instanceof ** operator checks:\ a) Object type\ b) Class access\ c) Variable scope\ d)
Package type\ Answer: a

83. Which is used to store key-value pairs?\ a) ArrayList\ b) LinkedList\ c) HashMap\ d) HashSet\
Answer: c

84. Java was officially released in:\ a) 1991\ b) 1995\ c) 2000\ d) 1998\ Answer: b

85. Which keyword is used to stop inheritance?\ a) final\ b) static\ c) private\ d) sealed\ Answer: a

86. A ** null ** reference means:\ a) Zero value\ b) No object\ c) Blank string\ d) Empty array\
Answer: b

87. What will happen if main method is missing?\ a) Compilation error\ b) Runtime error\ c) Nothing\
d) Success\ Answer: b

88. Which class is the parent of all classes in Java?\ a) Parent\ b) Object\ c) Base\ d) Super\ Answer: b

89. ** static ** methods belong to:\ a) Instance\ b) Object\ c) Class\ d) Constructor\ Answer: c

90. Java supports which type of inheritance?\ a) Multiple via interfaces\ b) Multiple via classes\ c)
None\ d) Hybrid only\ Answer: a

91. What is the wrapper class for int?\ a) Int\ b) Integer\ c) Number\ d) Float\ Answer: b

92. Which keyword is used to define a class constant?\ a) const\ b) static final\ c) define\ d) constant\
Answer: b

93. Which class is used to create GUI dialogs?\ a) JOptionPane\ b) JFrame\ c) DialogBox\ d) GUIBox\
Answer: a

94. Java is known as:\ a) Object-oriented\ b) Platform-dependent\ c) Fast compiled language\ d) OS-
specific\ Answer: a

95. Which of these can hold duplicate elements?\ a) HashMap\ b) HashSet\ c) List\ d) TreeSet\
Answer: c

96. Which Java version introduced Lambda expressions?\ a) Java 6\ b) Java 7\ c) Java 8\ d) Java 9\
Answer: c

4
97. What is the default package in Java?\ a) java.io\ b) java.util\ c) java.lang\ d) java.default\ Answer: c

98. Which stream handles object serialization?\ a) DataOutputStream\ b) FileWriter\ c)


ObjectOutputStream\ d) PrintWriter\ Answer: c

99. Which is not a feature of Java?\ a) Robust\ b) Portable\ c) Low-level\ d) Secure\ Answer: c

100. Java bytecode runs on:\ a) CPU directly\ b) Java compiler\ c) Java Virtual Machine\ d) Interpreter
only\ Answer: c

End of 100 MCQs for COS202 Java Programming. Let me know if you’d like this exported to PDF, Word,
or quizPDF foo

You might also like