Learn JAVA MCQs

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

Which keyword is used to define a constant in Java?

1) const

2) final

3) static

4) None of the above

Answer : final

Which of the following is a checked exception in Java?

1) ArrayIndexOutOfBoundsException

2) IOException

3) NullPointerException

4) ArithmeticException

Answer : IOException

What is the output of System.out.println(2 + 3 * 5);?

1) 25

2) 17

3) 15

4) None of the above

Answer : 17

Which keyword is used to call the parent class constructor in Java?

1) super

2) parent

3) this

4) None of the above

Answer : super

Which of the following is the correct way to declare a main method in Java?

1) public static void main(String[] args)

2) public void main(String[] args)

3) public main(String[] args)

4) None of the above

Answer : public static void main(String[] args)

What is the return type of the method that must be implemented in a Java Runnable interface?

1) void

2) int

3) Runnable

4) None of the above

Answer : void

Which operator is used to allocate memory for an object in Java?

1) malloc

2) new

3) alloc

4) None of the above

Answer : new

Which of the following is true about Java?

1) Java is an object-oriented programming language.

2) Java is platform-dependent.

3) Java does not support inheritance.

4) None of the above

Answer : Java is an object-oriented programming language.

Which method is used to compare two strings in Java?

1) compareTo()

2) compare()

3) equals()

4) None of the above

Answer : equals()

Which of the following is the correct way to declare a two-dimensional array in Java?

1) int[][] arr;

2) int arr[][];

3) Both 1 and 2

4) None of the above

Answer : Both 1 and 2