[go: up one dir, main page]

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

Java MCQs Explanations

The document provides explanations for multiple-choice questions (MCQs) related to basic Java concepts, covering topics such as data types, class declarations, loops, exceptions, and collections. Each question is followed by the correct answer and a brief explanation of the reasoning behind it. The content is structured into three sections, each containing ten questions.

Uploaded by

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

Java MCQs Explanations

The document provides explanations for multiple-choice questions (MCQs) related to basic Java concepts, covering topics such as data types, class declarations, loops, exceptions, and collections. Each question is followed by the correct answer and a brief explanation of the reasoning behind it. The content is structured into three sections, each containing ten questions.

Uploaded by

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

Explanations for Basic Java MCQs

Section 1: (Q1-Q10)

Q1.
Answer: B. String
Explanation: String is not a primitive data type. It is a
class in Java. Primitive types include int, float, boolean,
char, etc.

Q2.
Answer: A. class
Explanation: The class keyword is used to declare a new
class in Java.

Q3.
Answer: A. false
Explanation: Boolean variables have a default value of
false in Java.
Q4.
Answer: C. int[] arr = new int[5];
Explanation: This is the correct syntax for creating an
integer array with 5 elements in Java.

Q5.
Answer: B. equals()
Explanation: The equals() method compares the contents
of strings, while == compares references (memory
addresses).

Q6.
Answer: A. do-while loop
Explanation: A do-while loop executes the block at least
once, even if the condition is false.

Q7.
Answer: B. 8Java
Explanation: 4 + 4 is evaluated first to 8, and then
concatenated with "Java".
Q8.
Answer: C. default (package-private)
Explanation: When no access modifier is specified, Java
uses default/package-private access, meaning visible only
within the same package.

Q9.
Answer: A. PrintStream
Explanation: System.out is an instance of PrintStream,
used to print output to the console.

Q10.
Answer: B. println()
Explanation: println() is a method of the PrintStream
class to print data followed by a newline.

Section 2: Java MCQs (Q11–Q20)


Q11.
Answer: B. Object
Explanation: The Object class is the root of the class
hierarchy. Every class has Object as a superclass.

Q12.
Answer: C. extends
Explanation: The extends keyword is used to inherit a
class in Java.

Q13.
Answer: B. ArithmeticException
Explanation: Java throws an ArithmeticException when
dividing by zero.

Q14.
Answer: B. Thread
Explanation: To create a thread by extending, we use the
Thread class.
Q15.
Answer: C. Executes always
Explanation: The finally block always executes after the
try/catch blocks, whether an exception is thrown or not.

Q16.
Answer: B. run()
Explanation: The Runnable interface requires the
implementation of the run() method.

Q17.
Answer: B. new
Explanation: The new operator is used to create objects
in Java.

Q18.
Answer: C. java.util
Explanation: The Scanner class is part of the java.util
package used for input.

Q19.
Answer: A. ArrayIndexOutOfBoundsException
Explanation: This exception is thrown when accessing an
invalid array index.

Q20.
Answer: B. HashSet
Explanation: HashSet is a collection that does not allow
duplicate elements.

Section 3: Java MCQs (Q21–Q30)

Q21.
Answer: B. 12
Explanation: ++x increments x before multiplication. So +
+x becomes 6, and 6 * 2 = 12.

Q22.
Answer: B. [b]
Explanation: "a" is removed from the list, leaving only
"b".
Q23.
Answer: C. v
Explanation: str.charAt(2) returns the third character,
which is 'v' in "Java".

Q24.
Answer: B. 3
Explanation: arr.length gives the number of elements in
the array {1, 2, 3}.

Q25.
Answer: A. abc
Explanation: Strings are immutable in Java. concat("def")
creates a new string, but s remains unchanged.

Q26.
Answer: "Exception"
Explanation: 10 / 0 causes an ArithmeticException,
caught by the catch block, printing "Exception".

Q27.
Answer: B. B
Explanation: Key 1 is overwritten with value "B", so
map.get(1) returns "B".

Q28.
Answer: A. Running
Explanation: A new thread is started that runs the
lambda expression, printing "Running".

Q29.
Answer: C. NotSerializableException is thrown
Explanation: If MyClass does not implement Serializable,
Java throws NotSerializableException.

Q30.
Answer: D. 2
Explanation: HashSet does not allow duplicates, so only
"one" and "two" are added once. Size is 2.

You might also like