Learn JAVA MCQs

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

Which of the following is used to explicitly throw an exception in Java?

1) throw

2) throws

3) thrown

4) None of the above

Answer : throw

Which of the following is not an access modifier in Java?

1) private

2) protected

3) static

4) None of the above

Answer : static

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

1) Hello15

2) 15Hello

3) Hello10

4) None of the above

Answer : 15Hello

Which of the following is a valid syntax for a switch statement in Java?

1) switch (expression) { case value: break; }

2) switch expression { case value: break; }

3) switch(expression) case value: break;

4) None of the above

Answer : switch (expression) { case value: break; }

Which of the following is used to check whether a string is empty in Java?

1) isEmpty()

2) length()

3) isNull()

4) None of the above

Answer : isEmpty()

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

1) 1

2) 0

3) 2

4) None of the above

Answer : 1

Which of the following is a feature of the synchronized keyword in Java?

1) It is used to prevent thread interference.

2) It is used to prevent memory consistency errors.

3) Both 1 and 2

4) None of the above

Answer : Both 1 and 2

Which of the following is the correct way to create a thread in Java?

1) Implementing the Runnable interface

2) Extending the Thread class

3) Both 1 and 2

4) None of the above

Answer : Both 1 and 2

Which of the following is true about exception handling in Java?

1) Exceptions must be caught or declared to be thrown.

2) An exception is an event that occurs during the execution of a program.

3) Both 1 and 2

4) None of the above

Answer : Both 1 and 2

Which of the following is not a valid method in the String class?

1) substring()

2) charAt()

3) length()

4) None of the above

Answer : None of the above