Java Arrays Quiz - Multiple Choice Questions (MCQ)


Arrays are an essential data structure in Java, allowing you to store and manipulate multiple values of the same type. In this blog post, we present a Java Arrays Quiz comprising 15+ multiple-choice questions (MCQ). This quiz aims to assess your understanding of arrays in Java, including array declaration, initialization, accessing elements, and common array operations. Let's put your knowledge of Java arrays to the test! 

Learn and Master Java Programming: Learn Java Programming with Examples

Learn everything about Java 8 features: Java 8 Tutorial and Examples

Check out 100+ quiz questions: 100+ Quiz Questions to Test Your Java, Spring Boot, Microservices, Hibernate, REST API Skills

1. What is an Array in Java? 

a) A collection of elements with different types 

b) A collection of elements with the same type 

c) A resizable data structure 

d) A container for storing key-value pairs 

2. How do you declare an array in Java? 

a) int[] arr; 

b) int arr[]; 

c) int arr; 

d) Array<int> arr; 

3. What is the index range for the elements of an array in Java? 

a) 0 to length - 1

b) 1 to length 

c) -1 to length - 1 

d) 0 to length 

4. How do you access an element in an array in Java? 

a) By using the element's value 

b) By using the element's index 

c) By using the element's key 

d) By using the element's label

5. What happens if you try to access an array element with an index that is out of bounds? 

a) A runtime exception is thrown 

b) The program terminates abruptly 

c) The element value is set to null 

d) The element value is set to 0 

6. Which method is used to copy one array into another in Java? 

a) copy() 

b) clone() 

c) System.arraycopy() 

d) Arrays.copy() 

7. Can the length of an array be changed after its creation in Java? 

a) Yes, by using the resize() method 

b) Yes, by using the length property 

c) No, the length of an array is fixed after creation 

d) No, arrays in Java have a fixed length 

8. What symbol is used for a varargs method parameter?

a) ..

b) ...

c) --

d) ---

9. How many of the following are legal declarations?

[]double lion;
double[] tiger;
double bear[];
a) None 
b) One 
c) Two 
d) Three  

10. How do you determine the number of elements in an array?

int buses[] = new int[5];

a) buses.length

b) buses.length()

c) buses.size

d) buses.size()

11. Which of the following creates an empty two-dimensional array with dimensions 2×2?

a) int[][] blue = new int[2, 2];

b) int[][] blue = new int[2], [2];

c) int[][] blue = new int[2][2];

d) int[][] blue = new int[2 x 2];

12. What does this code output?

String[] nums = new String[] { "1", "9", "10" };
Arrays.sort(nums);
System.out.println(Arrays.toString(nums));

a) [1, 9, 10]

b) [1, 10, 9]

c) [10, 1, 9]

d) None of the above

13. How many of the following are legal declarations?

String lion [] = new String[] {"lion"};
String tiger [] = new String[1] {"tiger"};
String bear [] = new String[] {};
String cat [] = new String[0] {};

a) None

b) One

c) Two

d) Three

14. How many of the following are legal declarations?

float[] lion = new float[];
float[] tiger = new float[1];
float[] bear = new[] float;
float[] cat = new[1] float;

a) None

b) One

c) Two

d) Three 

15. Which is not a true statement about an array?

a) An array expands automatically when it is full.

b) An array is allowed to contain duplicate values.

c) An array understands the concept of ordered elements.

d) An array uses a zero index to reference the first element.

16. What is a possible output of the following code?

String[] strings = new String[2];
System.out.println(strings);

a) [null, null]

b) [,]

c) [Ljava.lang.String;@74a14482

d) None of the above

17. What does the following output?

String[] os = new String[] { "Mac", "Linux", "Windows" };
Arrays.sort(os);
System.out.println(Arrays.binarySearch(os, "Mac"));

a) 0

b) 1

c) 2

d) The output is not defined.

Conclusion

Congratulations on completing the Java Arrays Quiz! We hope it challenged your knowledge and provided valuable insights into arrays in Java. Arrays are a fundamental data structure in Java, enabling you to store and manipulate collections of elements.

Check out 100+ quiz questions: 100+ Quiz Questions to Test Your Java, Spring Boot, Microservices, Hibernate, REST API Skills

Keep practicing, keep learning, and become proficient in working with Java arrays!

Related Posts

  1. Java String Quiz
  2. Java Arrays Quiz
  3. Java Loops Quiz
  4. Java OOPS Quiz
  5. Java OOPS Quiz - Part 1
  6. Java OOPS Quiz - Part 2
  7. Java Exception Handling Quiz
  8. Java Collections Quiz
  9. Java Generics Quiz
  10. JDBC Quiz
  11. Java Lambda Expressions Quiz
  12. Java Functional Interfaces Quiz
  13. Java Streams API Quiz
  14. Java Date Time Quiz
  15. Java 8 Quiz

Comments

Spring Boot 3 Paid Course Published for Free
on my Java Guides YouTube Channel

Subscribe to my YouTube Channel (165K+ subscribers):
Java Guides Channel

Top 10 My Udemy Courses with Huge Discount:
Udemy Courses - Ramesh Fadatare