Learn JAVA MCQs

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

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

1) 53

2) 8

3) Error

4) None of the above

Answer : 53

Which of the following statements about the `final` keyword is true?

1) Final variables can be reassigned.

2) Final methods cannot be overridden.

3) Final classes can be inherited.

4) None of the above

Answer : Final methods cannot be overridden.

What is the output of System.out.println(5 < 3);?

1) true

2) false

3) Error

4) None of the above

Answer : false

Which of the following is a valid declaration of a constructor in Java?

1) public ClassName() {}

2) ClassName() {}

3) public void ClassName() {}

4) None of the above

Answer : public ClassName() {}

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

1) 10

2) 8

3) 20

4) None of the above

Answer : 10

Which of the following keywords is used to create a subclass in Java?

1) extends

2) inherits

3) implements

4) None of the above

Answer : extends

What is the output of System.out.println("123".charAt(0));?

1) 1

2) 2

3) 3

4) Error

Answer : 1

Which of the following is used to implement a thread-safe singleton class in Java?

1) synchronized

2) volatile

3) lazy initialization

4) All of the above

Answer : All of the above

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

1) 77

2) 10

3) 34

4) None of the above

Answer : 77

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

1) It is immutable.

2) It is synchronized.

3) It is mutable.

4) None of the above

Answer : It is mutable.