Learn JAVA MCQs

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

Which of the following exceptions is thrown when dividing by zero in Java?

1) NullPointerException

2) ArithmeticException

3) IndexOutOfBoundsException

4) None of the above

Answer : ArithmeticException

Which of the following is true about interfaces in Java?

1) Interfaces can have method bodies.

2) Interfaces can have static methods with bodies.

3) Interfaces cannot have static methods.

4) None of the above

Answer : Interfaces can have static methods with bodies.

Which of the following is a feature of Java?

1) Platform independence

2) Memory management

3) Both 1 and 2

4) None of the above

Answer : Both 1 and 2

What is the return type of the hashCode() method in Java?

1) String

2) int

3) long

4) None of the above

Answer : int

What is the output of System.out.println(3 % 2);?

1) 1

2) 0

3) 3

4) None of the above

Answer : 1

Which of the following statements is correct about Java?

1) Java is a compiled language.

2) Java is an interpreted language.

3) Java is both compiled and interpreted.

4) None of the above

Answer : Java is both compiled and interpreted.

Which of the following is true about garbage collection in Java?

1) It is manual.

2) It is automatic.

3) It is optional.

4) None of the above

Answer : It is automatic.

Which of the following is a reserved keyword in Java?

1) var

2) static

3) global

4) None of the above

Answer : static

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

1) 234

2) 23

3) 7

4) None of the above

Answer : 234

Which of the following is the correct way to handle exceptions in Java?

1) try-catch

2) throw-catch

3) handle-catch

4) None of the above

Answer : try-catch