Learn JAVA MCQs

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

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

1) 1

2) 4

3) 5

4) None of the above

Answer : 4

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

1) true

2) false

3) Error

4) None of the above

Answer : false

Which of the following is a keyword in Java?

1) string

2) String

3) StringBuilder

4) None of the above

Answer : None of the above

What is the output of System.out.println("abc".lastIndexOf("b"));?

1) 1

2) 2

3) 0

4) Error

Answer : 1

Which of the following can be used to declare a final variable in Java?

1) final int x;

2) const int x;

3) int final x;

4) None of the above

Answer : final int x;

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

1) 14

2) 12

3) 10

4) None of the above

Answer : 12

Which of the following is a valid way to create a map in Java?

1) Map<String, String> map = new HashMap<>();

2) Map map = new HashMap();

3) Map<String, String> map = new Map<>();

4) None of the above

Answer : Map<String, String> map = new HashMap<>();

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

1) 567

2) 12

3) Error

4) None of the above

Answer : 567

Which of the following is a built-in method of the String class in Java?

1) size()

2) length()

3) count()

4) None of the above

Answer : length()

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

1) true

2) false

3) Error

4) None of the above

Answer : true