Learn JAVA MCQs

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

Which of the following is not a valid Java identifier?

1) _myVar

2) 123abc

3) $myVar

4) myVar1

Answer : 123abc

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

1) 510

2) 15

3) Error

4) None of the above

Answer : 510

Which of the following is not a feature of Java?

1) Object-oriented

2) Platform-independent

3) Pointers

4) Multithreading

Answer : Pointers

Which method is used to convert a string into an integer in Java?

1) parseInt()

2) toInt()

3) valueOf()

4) None of the above

Answer : parseInt()

Which keyword is used to inherit a class in Java?

1) inherit

2) extends

3) implements

4) None of the above

Answer : extends

Which of the following statements is true about Java interfaces?

1) Interfaces can have method bodies.

2) Interfaces cannot be instantiated.

3) Interfaces do not support multiple inheritance.

4) None of the above

Answer : Interfaces cannot be instantiated.

What is the default value of an object reference in Java?

1) 0

2) null

3) undefined

4) None of the above

Answer : null

Which of the following loops is a post-tested loop in Java?

1) for

2) while

3) do-while

4) None of the above

Answer : do-while

Which keyword is used to define a subclass in Java?

1) extends

2) super

3) this

4) None of the above

Answer : extends

Which of the following exceptions is thrown when a thread is waiting, sleeping, or occupied, and the thread is interrupted?

1) InterruptedException

2) NullPointerException

3) IOException

4) None of the above

Answer : InterruptedException