Learn JAVA MCQs

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

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

1) 1

2) 3

3) 0

4) None of the above

Answer : 1

Which of the following is a valid declaration of a 2D array in Java?

1) int[][] arr = new int[5][5];

2) int[5][5] arr;

3) int arr[5][5];

4) None of the above

Answer : int[][] arr = new int[5][5];

Which of the following is true about Java?

1) Java supports multiple inheritance.

2) Java is platform-independent.

3) Java uses pointers.

4) None of the above

Answer : Java is platform-independent.

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

1) toUpper()

2) toUpperCase()

3) convertUpperCase()

4) None of the above

Answer : toUpperCase()

Which of the following is not a valid way to declare a variable in Java?

1) int x = 10;

2) String name = "Java";

3) int[] arr = {1, 2, 3};

4) int x: 10;

Answer : int x: 10;

What is the output of System.out.println(5 > 3 ? "Yes" : "No");?

1) Yes

2) No

3) true

4) None of the above

Answer : Yes

Which of the following is true about the main() method in Java?

1) It must be declared public.

2) It must be declared static.

3) It must have a return type of void.

4) All of the above

Answer : All of the above

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

1) java.util

2) java.lang

3) java.io

4) java.network

Answer : java.network

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

1) The overridden method must have the same return type.

2) The overridden method must have the same parameter list.

3) Both 1 and 2

4) None of the above

Answer : Both 1 and 2

Which of the following is true about arrays in Java?

1) An array can hold multiple data types.

2) Array indices start from 0.

3) The size of an array can change dynamically.

4) None of the above

Answer : Array indices start from 0.