Learn JAVA MCQs

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

Which of the following is used to convert a string to an integer in Java?

1) parseInt()

2) valueOf()

3) toInt()

4) None of the above

Answer : parseInt()

What is the output of System.out.println(Math.ceil(2.3));?

1) 3

2) 2

3) 2.3

4) None of the above

Answer : 3

Which of the following can be used to create a thread in Java?

1) Thread class

2) Runnable interface

3) Executor framework

4) All of the above

Answer : All of the above

What is the output of System.out.println(4 | 5);?

1) 1

2) 9

3) 5

4) None of the above

Answer : 9

Which of the following is not a primitive data type in Java?

1) int

2) float

3) double

4) String

Answer : String

Which of the following is true about method overriding in Java?

1) It allows a subclass to provide a specific implementation of a method.

2) It can change the return type.

3) Both 1 and 2

4) None of the above

Answer : It allows a subclass to provide a specific implementation of a method.

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

1) 8

2) 10

3) 6

4) None of the above

Answer : 10

Which of the following is a valid way to declare an array in Java?

1) int arr[];

2) int[] arr;

3) Both 1 and 2

4) None of the above

Answer : Both 1 and 2

What is the output of System.out.println(5 == 5.0);?

1) true

2) false

3) Error

4) None of the above

Answer : true

Which of the following is true about static variables in Java?

1) They belong to the class rather than any instance.

2) They are shared among all instances of a class.

3) Both 1 and 2

4) None of the above

Answer : Both 1 and 2