Learn JAVA MCQs

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

Which of the following is true about a final class in Java?

1) It cannot be subclassed.

2) It can have constructors.

3) Both 1 and 2

4) None of the above

Answer : Both 1 and 2

Which of the following keywords is used to inherit a class in Java?

1) extends

2) implements

3) inherits

4) None of the above

Answer : extends

What is the output of System.out.println("5" + 5);?

1) 55

2) 10

3) Error

4) None of the above

Answer : 55

Which of the following exceptions is thrown when an invalid array index is accessed?

1) NullPointerException

2) IndexOutOfBoundsException

3) ArrayIndexOutOfBoundsException

4) None of the above

Answer : ArrayIndexOutOfBoundsException

What is the output of System.out.println(5 / 2);?

1) 2

2) 2.5

3) Error

4) None of the above

Answer : 2

Which of the following is true about Java interfaces?

1) They can have method implementations.

2) They can have constants.

3) They can be instantiated.

4) None of the above

Answer : They can have constants.

What is the output of System.out.println(2 == "2");?

1) true

2) false

3) Error

4) None of the above

Answer : false

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

1) It is mutable.

2) It is synchronized.

3) It is slower than StringBuffer.

4) Both 2 and 3

Answer : It is mutable.

Which of the following statements is used to exit from a loop?

1) continue

2) break

3) return

4) exit

Answer : break

What is the output of System.out.println(1 + 2 + 3 + "4");?

1) 4

2) 1234

3) 10

4) None of the above

Answer : 1234