Learn JAVA MCQs

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

Which of the following is true regarding the Java interface?

1) It can have methods with body.

2) It can extend another interface.

3) Both 1 and 2

4) None of the above

Answer : It can extend another interface.

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

1) 32

2) 55

3) 7

4) None of the above

Answer : 55

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

1) extends

2) implements

3) inherits

4) None of the above

Answer : extends

What is the output of System.out.println(10 - 3 * 2);?

1) 4

2) 2

3) 6

4) None of the above

Answer : 4

Which of the following can be used to catch exceptions in Java?

1) try-catch

2) throw

3) finally

4) Both 1 and 2

Answer : Both 1 and 2

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

1) Ja

2) av

3) va

4) None of the above

Answer : av

Which of the following is not a valid access modifier in Java?

1) private

2) protected

3) internal

4) public

Answer : internal

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

1) 2.0

2) 2

3) Error

4) None of the above

Answer : 2.0

Which of the following keywords is used to declare a method that cannot be overridden?

1) final

2) static

3) abstract

4) None of the above

Answer : final

What is the output of System.out.println(4 & 2);?

1) 6

2) 0

3) 2

4) None of the above

Answer : Option 2