Java MCQs (Multiple Choice Questions) with Answers - Set II

Java MCQs ( Multiple Choice Questions ) with Answers - Set II - CodingHumans

Set II moves from Java history to the everyday things you write in code: data types, operators, strings, arrays and exceptions. A lot of these are "what does this print?" questions, because that is what most written tests and online assessments like to ask.

Try to work out each answer on paper before you tap an option. If you get one wrong, copy the snippet into an editor and run it. Seeing the output yourself sticks much better than reading the explanation.

Note: the older version of this page repeated questions from Set I by mistake. In October 2026 we replaced it with fifteen new questions, and every output below has been checked by running it.

How to use this set: pick an option for each question. You will see straight away whether it is right, with a short note on why. There are 15 questions.

What this set covers

  • Primitive types and default values
  • Integer division, string concatenation and char arithmetic
  • String pool and == versus equals()
  • Arrays and runtime exceptions
  • Checked exceptions and the finally block
  • final, static and method overloading

Java MCQs with answers and explanations

Q1. How many bits does an int take in Java?

a) 32

b) 16

c) 64

d) It depends on the operating system

Q2. What is the default value of a boolean instance variable that you never assign?

a) null

b) false

c) true

d) It will not compile

Q3. What does System.out.println(10 / 4); print?

a) 3

b) 2

c) 2.5

d) 2.0

Q4. What does this line print?

System.out.println(1 + 2 + "3" + 4 + 5);

a) 339

b) 12345

c) 3345

d) 15

Q5. What is the output?

String s1 = "java";
String s2 = "java";
String s3 = new String("java");
System.out.println((s1 == s2) + " " + (s1 == s3));

a) false false

b) true true

c) false true

d) true false

Q6. Which keyword stops a class from being extended?

a) private

b) static

c) final

d) abstract

Q7. Which modifier is NOT allowed on a constructor?

a) public

b) static

c) private

d) protected

Q8. When does Java decide which overloaded method to call?

a) At compile time

b) When the class is loaded

c) When the garbage collector runs

d) At run time

Q9. What happens when this code runs?

int[] a = new int[3];
System.out.println(a[3]);

a) It prints null

b) It prints 0

c) It throws ArrayIndexOutOfBoundsException

d) It does not compile

Q10. What is printed?

char c = 'A';
c += 2;
System.out.println(c);

a) C

b) 67

c) B

d) Compilation error

Q11. Which of these collections does NOT allow duplicate elements?

a) Vector

b) LinkedList

c) ArrayList

d) HashSet

Q12. In which case will the finally block NOT run?

a) When System.exit() is called inside the try block

b) When an exception is thrown and caught

c) When no exception is thrown

d) When the try block returns a value

Q13. Which of these is a checked exception?

a) IOException

b) NullPointerException

c) ArrayIndexOutOfBoundsException

d) ArithmeticException

Q14. What does this print?

int x = 5;
System.out.println(x++ + ++x);

a) 13

b) 11

c) 10

d) 12

Q15. Since which Java version can an interface have default methods with a body?

a) Java 11

b) Java 7

c) Java 5

d) Java 8

Quick revision notes

  • Sizes: byte 8, short 16, int 32, long 64, float 32, double 64 bits; char is 16 bits.
  • int / int is integer division. Add a decimal to get a double result.
  • Once a String joins a + expression, everything to its right is joined as text.
  • Use equals() to compare strings. == only checks whether two references point to the same object.
  • Checked exceptions (like IOException) must be handled; RuntimeExceptions need not be.

Frequently asked questions

Why do Java tests ask so many output questions?

Because they check whether you really understand evaluation order, types and object references, not just definitions. Running small snippets yourself is the fastest way to get good at them.

Is == ever right for comparing strings?

Only when you really want to know if two variables point to the same object. For checking text, always use equals(), or equalsIgnoreCase() when case does not matter.

What should I study after this set?

Try Set III for interfaces, JDBC and exceptions, then move to our Core Java interview questions and the Java Collections parts.

Java MCQs: Set 1 | Set 2 | Set 3
← Previous: Set 1  |  Next: Set 3 →
See everything in one place: MCQ Practice

Comments

Answered 0/0Correct 0