Learn JAVA MCQs

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

Which of the following is used to find the length of an array in Java?

1) length()

2) size()

3) length

4) None of the above

Answer : length

Which of the following is a method of the Object class?

1) clone()

2) finalize()

3) wait()

4) All of the above

Answer : All of the above

Which exception is thrown when an array is accessed with an illegal index in Java?

1) NullPointerException

2) ArrayIndexOutOfBoundsException

3) IllegalArgumentException

4) None of the above

Answer : ArrayIndexOutOfBoundsException

Which of the following is the correct syntax to create a new object of a class in Java?

1) ClassName obj = new ClassName();

2) ClassName obj = ClassName();

3) ClassName obj = new ClassName;

4) None of the above

Answer : ClassName obj = new ClassName();

Which of the following is true about inheritance in Java?

1) A class can inherit from more than one class.

2) A class can inherit from one class only.

3) A class can inherit from both a class and an interface.

4) None of the above

Answer : A class can inherit from one class only.

Which keyword is used to refer to the immediate parent class in Java?

1) parent

2) super

3) this

4) None of the above

Answer : super

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

1) true

2) false

3) null

4) None of the above

Answer : false

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

1) A final class can be inherited.

2) A final method can be overridden.

3) A final variable cannot be changed.

4) None of the above

Answer : A final variable cannot be changed.

Which of the following is not a valid primitive type in Java?

1) char

2) byte

3) integer

4) None of the above

Answer : integer

Which of the following is used to get a string representation of an object in Java?

1) toString()

2) convert()

3) toObject()

4) None of the above

Answer : toString()