Learn JAVA MCQs

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

What is the output of System.out.println("Java".startsWith("Ja"));?

1) true

2) false

3) Error

4) None of the above

Answer : true

Which of the following is true about Java exceptions?

1) They are objects.

2) They are used to indicate errors.

3) Both 1 and 2

4) None of the above

Answer : Both 1 and 2

What is the output of System.out.println(8 / 3);?

1) 2

2) 2.666

3) 3

4) None of the above

Answer : 2

Which of the following is the correct syntax to define a method in a class?

1) void methodName() {}

2) public void methodName() {}

3) methodName() {}

4) None of the above

Answer : public void methodName() {}

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

1) helloworld

2) HELLOWORLD

3) HelloWorld

4) None of the above

Answer : helloworld

Which of the following is the correct way to create a multi-dimensional array in Java?

1) int[][] arr = new int[3][4];

2) int[3][4] arr = new int[][];

3) int arr[3][4] = new int[][];

4) None of the above

Answer : int[][] arr = new int[3][4];

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

1) va

2) Ja

3) ava

4) None of the above

Answer : va

Which of the following is a valid identifier in Java?

1) var-name

2) 2ndVar

3) var_name

4) None of the above

Answer : var_name

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

1) 55

2) 105

3) Error

4) None of the above

Answer : 105

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

1) public

2) private

3) protected

4) sealed

Answer : sealed