Learn JAVA MCQs

Prepare JAVA MCQs (Multiple choice Questions) for exam and job interviews.

What is the output of System.out.println("Hello".substring(1, 3));?

1) He

2) el

3) llo

4) None of the above

Answer : el

Which of the following is used to create a new thread in Java?

1) Runnable interface

2) Thread class

3) Both 1 and 2

4) None of the above

Answer : Both 1 and 2

Which of the following is true about the finally block in Java?

1) It is executed only when an exception is thrown.

2) It is executed even if no exception is thrown.

3) It is executed only after the try block completes.

4) None of the above

Answer : It is executed even if no exception is thrown.

Which of the following is not a valid type of loop in Java?

1) for loop

2) while loop

3) do-while loop

4) None of the above

Answer : None of the above

Which of the following is used to stop the execution of a loop in Java?

1) break

2) continue

3) exit

4) None of the above

Answer : break

Which of the following is true about the String class in Java?

1) Strings are mutable.

2) Strings are immutable.

3) Strings are stored in heap memory.

4) None of the above

Answer : Strings are immutable.

Which of the following is a wrapper class in Java?

1) int

2) Integer

3) float

4) None of the above

Answer : Integer

Which of the following is not a primitive type in Java?

1) int

2) char

3) String

4) None of the above

Answer : String

What is the output of System.out.println(10 << 2);?

1) 40

2) 20

3) 80

4) None of the above

Answer : 40

Which of the following is used to create an instance of a class in Java?

1) new

2) create

3) instantiate

4) None of the above

Answer : new