Learn JAVA MCQs

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

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

1) 0

2) null

3) undefined

4) None of the above

Answer : None of the above

Which of the following is true about polymorphism in Java?

1) Polymorphism allows objects to be treated as instances of their parent class.

2) Polymorphism allows methods to be overridden.

3) Both 1 and 2

4) None of the above

Answer : Both 1 and 2

What is the output of System.out.println("Hello".charAt(1));?

1) e

2) H

3) l

4) None of the above

Answer : e

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

1) It refers to the current object.

2) It refers to the parent class.

3) It can be used to call a constructor.

4) Both 1 and 3

Answer : Both 1 and 3

Which of the following is not a valid scope of a variable in Java?

1) Local scope

2) Global scope

3) Instance scope

4) None of the above

Answer : Global scope

Which of the following is true about the break statement in Java?

1) It terminates the current loop.

2) It skips the current iteration.

3) It returns control to the caller.

4) None of the above

Answer : It terminates the current loop.

Which of the following is not a valid access specifier in Java?

1) public

2) protected

3) default

4) None of the above

Answer : default

Which of the following is used to handle exceptions in Java?

1) try-catch block

2) throw block

3) throws block

4) None of the above

Answer : try-catch block

Which of the following is a feature of encapsulation in Java?

1) It allows access to the data directly.

2) It hides the internal implementation of an object.

3) It allows multiple inheritance.

4) None of the above

Answer : It hides the internal implementation of an object.

Which of the following is true about method overriding in Java?

1) The overridden method must have the same name.

2) The overridden method must have a different name.

3) The overridden method must be private.

4) None of the above

Answer : The overridden method must have the same name.