Learn JAVA MCQs

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

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

1) Hello World

2) HelloWorld

3) Hello World

4) None of the above

Answer : Hello World

Which of the following statements about Java methods is true?

1) They must have a return type.

2) They can have zero or more parameters.

3) Both 1 and 2

4) None of the above

Answer : Both 1 and 2

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

1) 7

2) 5

3) 1

4) None of the above

Answer : 7

Which of the following is the correct way to handle multiple exceptions in a single catch block?

1) catch (Exception | IOException e)

2) catch (Exception e, IOException e)

3) catch (Exception e) catch (IOException e)

4) None of the above

Answer : catch (Exception | IOException e)

What is the output of System.out.println(10 == 10.0);?

1) true

2) false

3) Error

4) None of the above

Answer : true

Which of the following is the correct way to start a thread in Java?

1) t.start();

2) t.run();

3) t.begin();

4) None of the above

Answer : t.start();

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

1) 123

2) 6

3) 32

4) None of the above

Answer : 123

Which of the following is used to create a new thread in Java?

1) Thread class

2) Runnable interface

3) Both 1 and 2

4) None of the above

Answer : Both 1 and 2

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

1) 4

2) 5

3) 3

4) None of the above

Answer : 4

Which of the following is true about the `synchronized` keyword?

1) It is used to control access to a block of code.

2) It can be applied to methods.

3) Both 1 and 2

4) None of the above

Answer : Both 1 and 2