Java Array MCQs with answers Page - 3

You will find multiple-choice questions (MCQs) related to #Java Array here. Go through these questions to prepare effectively for your upcoming exams and interviews.

To view the correct answer for any question, simply click the "Show Answer" button.

Have a question to share? Click on "Add Question" to contribute!

A

Admin • 828.03K Points
Coach

Q. Which of the following statements is used to create an array of 10 integers?

  • (A) int[10] arr = new int[];
  • (B) int arr = new int[10];
  • (C) int arr[] = new int[10];
  • (D) int arr = int[10];

A

Admin • 828.03K Points
Coach

Q. What is the default value of elements in an array of objects?

  • (A) 0
  • (B) null
  • (C) empty string
  • (D) depends on the object

A

Admin • 828.03K Points
Coach

Q. Which method is used to sort an array in Java?

  • (A) Collections.sort()
  • (B) Arrays.sort()
  • (C) array.sort()
  • (D) Sort.array()

A

Admin • 828.03K Points
Coach

Q. What is the result of this code?
int[] arr = {10, 20, 30};
System.out.println(arr.length);

  • (A) 2
  • (B) 3
  • (C) 10
  • (D) Compile-time error

A

Admin • 828.03K Points
Coach

Q. What is true about an array declared as `int[] a = null;`?

  • (A) It is an empty array
  • (B) It has size 0
  • (C) It has not been initialized
  • (D) It contains only 0s

A

Admin • 828.03K Points
Coach

Q. How to access the last element of an array 'arr'?

  • (A) arr[arr.length]
  • (B) arr[arr.length - 1]
  • (C) arr[length(arr)]
  • (D) arr[-1]

A

Admin • 828.03K Points
Coach

Q. What is printed?
int[] arr = new int[4];
System.out.print(arr[3]);

  • (A) 3
  • (B) 0
  • (C) null
  • (D) undefined

A

Admin • 828.03K Points
Coach

Q. Which of the following can store both primitives and objects?

  • (A) int[]
  • (B) Object[]
  • (C) float[]
  • (D) boolean[]

A

Admin • 828.03K Points
Coach

Q. What will happen if you try to access arr[-1]?

  • (A) Returns first element
  • (B) Returns last element
  • (C) Throws ArrayIndexOutOfBoundsException
  • (D) Returns null

A

Admin • 828.03K Points
Coach

Q. Which of the following declares and initializes an array correctly?

  • (A) int arr[] = (1,2,3);
  • (B) int arr[] = new int[3]{1,2,3};
  • (C) int arr[] = {1, 2, 3};
  • (D) array arr = [1,2,3];
What's Tag

As you may know, questions are organized under broad categories. Each category can include various types of questions. For example, the "History" category might contain questions about the Revolt of 1857, Shivaji Maharaj, Ancient History, Buddhism, and more.

To further refine this organization, we've introduced tags, which act as sub-categories to group questions more specifically.

Verified users can add tags to any question. If you have any suggestions regarding this system, we'd love to hear from you. Contact Us

Learn More