Learn JAVA MCQs

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

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

1) 4

2) 5

3) Error

4) None of the above

Answer : 4

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

1) try-catch

2) catch-try

3) throw-catch

4) None of the above

Answer : try-catch

What will happen if you try to divide a number by zero in Java?

1) Runtime error

2) Compile time error

3) No error

4) None of the above

Answer : Runtime error

Which of the following keywords is used to create a subclass?

1) extends

2) super

3) this

4) None of the above

Answer : extends

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

1) 25

2) 53

3) Error

4) None of the above

Answer : 53

What is the default value of a boolean variable in Java?

1) true

2) false

3) 0

4) 1

Answer : false

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

1) 111

2) 21

3) Error

4) None of the above

Answer : 111

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

1) Integer.parseInt()

2) Integer.valueOf()

3) Both 1 and 2

4) None of the above

Answer : Both 1 and 2

What is the output of System.out.println(7 | 3);?

1) 4

2) 5

3) 6

4) None of the above

Answer : 7

Which of the following is not a valid string method in Java?

1) substring()

2) concat()

3) charAt()

4) combine()

Answer : combine()