Learn JAVA MCQs

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

Which of the following is true about the super keyword in Java?

1) It refers to the parent class.

2) It is used to call the parent class constructor.

3) Both 1 and 2

4) None of the above

Answer : Both 1 and 2

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

1) true

2) false

3) 1

4) None of the above

Answer : true

Which of the following is used to declare a method that does not return a value in Java?

1) void

2) null

3) None

4) None of the above

Answer : void

Which of the following is used to get the class of an object in Java?

1) getClass()

2) getObject()

3) getName()

4) None of the above

Answer : getClass()

Which of the following is true about the finalize() method in Java?

1) It is used for cleanup before an object is garbage collected.

2) It is automatically called by the JVM.

3) Both 1 and 2

4) None of the above

Answer : Both 1 and 2

Which of the following is true about static blocks in Java?

1) They are executed when the class is loaded.

2) They can be used to initialize static variables.

3) Both 1 and 2

4) None of the above

Answer : Both 1 and 2

What is the output of System.out.println(Math.pow(2, 3));?

1) 6

2) 8

3) 9

4) None of the above

Answer : 8

Which of the following is true about the equals() method in Java?

1) It compares object references.

2) It compares object content.

3) Both 1 and 2

4) None of the above

Answer : It compares object content.

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

Which method must be implemented by all threads in Java?

1) run()

2) start()

3) execute()

4) None of the above

Answer : run()