Learn JAVA MCQs

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

What is the output of System.out.println(10/0);?

1) 0

2) Infinity

3) Error

4) Exception

Answer : Exception

Which method is called when an object is created in Java?

1) new()

2) init()

3) constructor()

4) None of the above

Answer : None of the above

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

1) 0

2) null

3) Depends on the type

4) Undefined

Answer : Depends on the type

What is the output of System.out.println("Java".substring(1, 3));?

1) av

2) va

3) Ja

4) None of the above

Answer : av

Which of the following is used to achieve multiple inheritance in Java?

1) Interfaces

2) Classes

3) Both 1 and 2

4) None of the above

Answer : Interfaces

What is the output of System.out.println(Math.abs(-10));?

1) 10

2) -10

3) Error

4) None of the above

Answer : 10

What is the output of System.out.println(20 << 3);?

1) 160

2) 240

3) 320

4) Error

Answer : 160

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

1) It is used to initialize objects.

2) It must have a return type.

3) It is called manually.

4) None of the above

Answer : It is used to initialize objects.

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

1) 5

2) 10

3) 15

4) Error

Answer : 15

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

1) Thread class

2) Runnable interface

3) Both 1 and 2

4) None of the above

Answer : Both 1 and 2