Java Array MCQs with answers Page - 8

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 • 825.56K Points
Coach

Q. How to iterate through a String array using enhanced for loop?

  • (A) for (int i : array)
  • (B) for (String s : array)
  • (C) for (char c : array)
  • (D) for (Object o : array)

A

Admin • 825.56K Points
Coach

Q. Can we store mixed types in a single array in Java?

  • (A) Yes, in primitive arrays
  • (B) Yes, if all are objects
  • (C) Yes, in all cases
  • (D) No

A

Admin • 825.56K Points
Coach

Q. What will this print?
String[] names = new String[2];
names[1] = "John";
System.out.println(names[0]);

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

A

Admin • 825.56K Points
Coach

Q. Which method copies part of an array into a new one?

  • (A) Arrays.extract()
  • (B) Arrays.copyOfRange()
  • (C) Arrays.clone()
  • (D) Arrays.splice()

A

Admin • 825.56K Points
Coach

Q. Which of the following arrays will throw an exception when accessed?

  • (A) int[] a = new int[0]; a[0];
  • (B) int[] a = new int[2]; a[1];
  • (C) int[] a = {1, 2}; a[2];
  • (D) int[] a = new int[]{1}; a[0];

A

Admin • 825.56K Points
Coach

Q. How can you increase the size of an array in Java?

  • (A) By using resize() method
  • (B) By reallocating with a new array
  • (C) Using array.grow()
  • (D) Using array.expand()

A

Admin • 825.56K Points
Coach

Q. What happens if you assign an array to another variable?

  • (A) The array is copied
  • (B) The reference is shared
  • (C) A new object is created
  • (D) Compiler error

A

Admin • 825.56K Points
Coach

Q. Which of the following can store null values?

  • (A) int[]
  • (B) double[]
  • (C) String[]
  • (D) char[]

A

Admin • 825.56K Points
Coach

Q. Which import is required for Arrays.sort()?

  • (A) import java.lang.*;
  • (B) import java.io.*;
  • (C) import java.util.Arrays;
  • (D) No import needed

A

Admin • 825.56K Points
Coach

Q. Which of the following arrays is correctly initialized with values?

  • (A) int[] a = new int[3]{1,2,3};
  • (B) int a[] = {1,2,3};
  • (C) int a[3] = {1,2,3};
  • (D) int a() = new int[]{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