Learn JAVA MCQs

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

What is the output of System.out.println("Java".equalsIgnoreCase("java"));?

1) true

2) false

3) Error

4) None of the above

Answer : true

Which of the following is used to handle exceptions in Java?

1) try-catch

2) throw

3) throws

4) All of the above

Answer : All of the above

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

1) H

2) e

3) l

4) Error

Answer : e

Which of the following is used to read a string from the user in Java?

1) Scanner

2) BufferedReader

3) Both 1 and 2

4) None of the above

Answer : Both 1 and 2

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

1) 5

2) 6

3) 7

4) Error

Answer : 5

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

1) It can have a return type.

2) It can have a void return type.

3) Both 1 and 2

4) None of the above

Answer : Both 1 and 2

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

1) 5

2) 4

3) 6

4) Error

Answer : 5

What is the output of System.out.println("abc".replace("a", "z"));?

1) zbc

2) abc

3) Error

4) None of the above

Answer : zbc

Which of the following is used to define an abstract method in Java?

1) abstract

2) final

3) static

4) None of the above

Answer : abstract

What is the output of System.out.println(Math.max(10, 20));?

1) 10

2) 20

3) 30

4) Error

Answer : 20