Learn JAVA MCQs

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

Which of the following is used to define constants in Java?

1) const

2) final

3) static

4) None of the above

Answer : final

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

1) J

2) a

3) v

4) None of the above

Answer : v

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

1) It is used for garbage collection.

2) It is called before an object is destroyed.

3) It can be overridden.

4) All of the above

Answer : All of the above

Which of the following is true about the StringBuilder class in Java?

1) It is mutable.

2) It is immutable.

3) It cannot be resized.

4) None of the above

Answer : It is mutable.

Which of the following is used to throw an exception in Java?

1) throw

2) throws

3) try

4) None of the above

Answer : throw

Which of the following is used to catch an exception in Java?

1) catch

2) throw

3) throws

4) None of the above

Answer : catch

What is the output of System.out.println(5 << 2);?

1) 20

2) 40

3) 10

4) None of the above

Answer : 20

Which of the following is used to declare an abstract method in Java?

1) abstract

2) final

3) static

4) None of the above

Answer : abstract

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

1) It returns a string representation of an object.

2) It can be overridden.

3) Both 1 and 2

4) None of the above

Answer : Both 1 and 2

Which of the following is not a valid modifier in Java?

1) public

2) protected

3) private

4) static final

Answer : static final