Learn JAVA MCQs

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

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

1) Thread t = new Thread(); t.start();

2) t.start(); Thread t = new Thread();

3) new Thread().run();

4) None of the above

Answer : Thread t = new Thread(); t.start();

What is the output of System.out.println("A".compareTo("B"));?

1) -1

2) 1

3) 0

4) None of the above

Answer : -1

Which of the following is true about Java constructors?

1) They cannot return a value.

2) They can be overloaded.

3) Both 1 and 2

4) None of the above

Answer : Both 1 and 2

What is the output of System.out.println(0.1 + 0.2 == 0.3);?

1) true

2) false

3) Error

4) None of the above

Answer : false

Which of the following is a part of the Java Collection Framework?

1) Map

2) Set

3) List

4) All of the above

Answer : All of the above

What is the output of System.out.println(8 >> 1);?

1) 4

2) 8

3) 16

4) None of the above

Answer : 4

Which of the following is the correct way to declare a StringBuilder in Java?

1) StringBuilder sb = new StringBuilder();

2) StringBuilder sb = new String();

3) StringBuilder sb;

4) None of the above

Answer : StringBuilder sb = new StringBuilder();

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

1) 10

2) 8

3) 6

4) None of the above

Answer : 10

Which of the following methods can be 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(10 == 10.0);?

1) true

2) false

3) Error

4) None of the above

Answer : true