Learn JAVA MCQs

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

What is the output of System.out.println("Hello".toLowerCase());?

1) HELLO

2) hello

3) HeLLo

4) None of the above

Answer : hello

Which of the following is not a valid way to start a thread in Java?

1) Extending the Thread class

2) Implementing the Runnable interface

3) Using a lambda expression

4) None of the above

Answer : None of the above

Which of the following is used to stop a thread in Java?

1) stop()

2) sleep()

3) interrupt()

4) None of the above

Answer : interrupt()

Which of the following is true about constructors in Java?

1) Constructors can be overloaded.

2) Constructors cannot be overloaded.

3) Constructors can return values.

4) None of the above

Answer : Constructors can be overloaded.

Which of the following is true about packages in Java?

1) A package can contain multiple classes.

2) A package can contain other packages.

3) Packages are used to avoid name conflicts.

4) All of the above

Answer : All of the above

Which of the following is used to read a file in Java?

1) FileReader

2) BufferedReader

3) Both 1 and 2

4) None of the above

Answer : Both 1 and 2

Which of the following is not a valid keyword in Java?

1) new

2) switch

3) goto

4) None of the above

Answer : goto

What is the output of System.out.println(10 >>> 2);?

1) 2

2) 2.5

3) 40

4) None of the above

Answer : 2

Which of the following is true about the instanceof operator in Java?

1) It checks whether an object is an instance of a class.

2) It is used for casting.

3) It compares two objects.

4) None of the above

Answer : It checks whether an object is an instance of a class.

Which of the following is not a valid return type for a method in Java?

1) int

2) void

3) Null

4) None of the above

Answer : Null