Practice high-yield Programming & Software Development MCQs on Array — Part 1 with worked academic solutions for FPSC, PPSC, NTS, NITB, PTS.
Questions
40
Difficulty Level
Exam-Level
Target Exams
FPSC, PPSC, NTS...
Estimated Time
48 mins
Exam-Level FPSC PPSC NTS NITB PTS
Verified for Commission Syllabus • Oct 14, 2026
40
Verified Practice Questions
Interactive test mode with detailed academic worked solutions
Live Progress|0/40 answered
✓0 correct
✗0 wrong
0% score
🎉 Set complete! All 40 questions answered.
Question 1 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
How do you declare a one-dimensional array in Java?
Correct Answer: Option A — int[] myArray
Detailed Academic Explanation:
In Java, a one-dimensional array is declared by specifying the type of elements followed by square brackets and then the array name. The correct syntax is: type[] arrayName; Option A follows this syntax and is the correct way to declare a one-dimensional array in Java. Option B is also a valid syntax but is less commonly used. Both Option A and Option B are equivalent. Option C is incorrect as it attempts to use generics syntax, which is not allowed for arrays in Java. Option D is incorrect because Option C is not a valid way to declare an array.
💡Key Conceptual Anchor:Array
Question 2 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which of the following is a valid declaration and initialization of a String array in Java?
Correct Answer: Option D — Both A and B
Detailed Academic Explanation:
Option A initializes a String array named "names" with three elements: "Alice", "Bob", and "Charlie". This is a valid and commonly used syntax for declaring and initializing a String array in Java. Option B: String names[] = new String[]{"Alice", "Bob", "Charlie"}; This syntax is also valid for declaring and initializing a String array in Java. However, it's less commonly used. Option C: String[3] names = {"Alice", "Bob", "Charlie"}; This syntax is invalid. In Java, when declaring an array, the size should not be specified in the square brackets.
💡Key Conceptual Anchor:Array
Question 3 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which of the following statements is true about arrays in Java?
Correct Answer: Option D — Arrays are objects of type Array.
Detailed Academic Explanation:
In Java, arrays are objects. They are instances of classes that extend the abstract class java.lang.Object. However, arrays in Java are implemented as objects of a specific type called "Array". This means that arrays in Java are indeed objects, but they are not instances of the Array class; rather, they are instances of classes that are automatically generated by the Java Virtual Machine (JVM) when arrays are created. Option A: Arrays can change in size after initialization. In Java, once an array is initialized with a specific size, that size cannot be changed. Arrays have a fixed length determined at the time of creation. While you can create a new array with a different size and copy elements from the old array to the new one to achieve a similar effect, the original array itself cannot change its size. Option B: Arrays can store elements of different types. In Java, arrays are homogeneous data structures, meaning they can only store elements of the same type. When you declare an array, you specify the type of elements it can hold. All elements in the array must be compatible with this type. Option C: Arrays can have a negative length. In Java, array lengths must be non-negative integers. It is not possible to declare an array with a negative length. Attempting to do so will result in a compilation error. Therefore, the correct answer is Option D: Arrays are objects of type Array. Arrays in Java are indeed objects, but they are instances of classes that are automatically generated by the Java Virtual Machine (JVM) when arrays are created. They are not instances of the Array class itself, but they are objects nonetheless.
💡Key Conceptual Anchor:Array
Question 4 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
In Java arrays are
Correct Answer: Option A — objects
Detailed Academic Explanation:
In java an array is a container object that holds a fixed number of values of a single type. The length of an array is established when the array is created. After creation, its length is fixed.
💡Key Conceptual Anchor:Array
Question 5 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which one of the following is a valid statement?
Correct Answer: Option B — char[] c = new char[5]
Detailed Academic Explanation:
The syntax for declaring and creating an array variable in java is: dataType[] arrayRefVar = new dataType[arraySize]; Thus, option (A) and option (C) is syntactically wrong as parentheses( ( ) ) is used instead of square brackets( [ ] ). Option (D) is incorrect as the size of the array is missing.
💡Key Conceptual Anchor:Array
Question 6 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the result of compiling and running the following code? public class Test{ public static void main(String[] args){ int[] a = new int[0]; System.out.print(a.length); } }
Correct Answer: Option A — 0
Detailed Academic Explanation:
Step 1: Declare a public class named Test . Step 2: Define the main method with the public and static modifiers and a parameter of type String array named args . Step 3: Declare an array variable a of type int[] . Step 4: Initialize the array a with a size of 0 using the new keyword. Step 5: Print the length of the array a using the length property. Therefore, when you compile and run the code, the output will be: 0 This output corresponds to the length of the array a , which is 0.
💡Key Conceptual Anchor:Array
Question 7 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output? public class Test{ public static void main(String[] args){ int[] x = new int[3]; System.out.println("x[0] is " + x[0]); } }
Correct Answer: Option C — The program runs fine and displays x[0] is 0.
Detailed Academic Explanation:
Program is syntactically correct, so no error. In java, if the array is not initialized at the time of declaration and creation then all the elements of the array are initialized to 0 by default.
💡Key Conceptual Anchor:Array
Question 8 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the output of the following code? public class Test{ public static void main(String args[]){ double[] myList = {1, 5, 5, 5, 5, 1}; double max = myList[0]; int indexOfMax = 0; for(int i = 1; i < myList.length; i++){ if(myList[i] > max){ max = myList[i]; indexOfMax = i; } } System.out.println(indexOfMax); } }
Correct Answer: Option B — 1
Detailed Academic Explanation:
In the given program. Line 7 : if(myList[i] > max) execute only on time when i =1; when i = 1 then myList[i] = 5 and max = 1( so the statement is true and if block will be executed ). Then, max = myList[i] = 5 and indexOfMax = i = 1. After that if statement always false. so indexOfMax value remain 1. Therefore the value of indexOfMax is 1 at end of the for loop.
💡Key Conceptual Anchor:Array
Question 9 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is output of the following code: public class Test{ public static void main(String[] args){ int[] x = {120, 200, 016 }; for(int i = 0; i < x.length; i++) System.out.print(x[i] + " "); } }
Correct Answer: Option B — 120 200 14
Detailed Academic Explanation:
016 is an octal number. The prefix 0 indicates that a number is in octal.
💡Key Conceptual Anchor:Array
Question 10 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output? public class Test{ public static void main(String[] args){ int[] a = new int[4]; a[1] = 1; a = new int[2]; System.out.println("a[1] is " + a[1]); } }
Correct Answer: Option C — a[1] is 0
Detailed Academic Explanation:
After executing the statement a = new int [ 2 ], a refers to int [ 2 ]. The default value for a [ 0 ] and a [ 1 ] is 0.
💡Key Conceptual Anchor:Array
Question 11 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What would be the result of attempting to compile and run the following code? public class HelloWorld{ public static void main(String[] args){ double[] x = new double[]{1, 2, 3}; System.out.println("Value is " + x[1]); } }
Correct Answer: Option D — The program compiles and runs fine and the output
Detailed Academic Explanation:
new double []{1, 2, 3} is correct. This is the syntax I have not covered in this edition, but will be covered in the future edition. In this question, double [] x = new double []{1, 2, 3} is equivalent to double [] x = {1, 2, 3};
💡Key Conceptual Anchor:Array
Question 12 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which will legally declare, construct, and initialize an array?
Correct Answer: Option D — int myList [] = {4, 3, 7}
Detailed Academic Explanation:
The only legal array declaration and assignment statement is Option D Option A is wrong because it initializes an int array with String literals. Option B is wrong because it uses something other than curly braces for the initialization. Option C is wrong because it provides initial values for only one dimension, although the declared array is a two-dimensional array.
💡Key Conceptual Anchor:Array
Question 13 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the program? public class Test{ public static void main(String [] args){ String s1 = args[1]; String s2 = args[2]; String s3 = args[3]; String s4 = args[4]; System.out.print(" args[2] = " + s2); } } and the command-line invocation is C:Java> java Test 1 2 3 4
Correct Answer: Option D — An exception is thrown at runtime.
Detailed Academic Explanation:
An exception is thrown because in the code String s4 = args [ 4 ];, the array index (the fifth element) is out of the bounds. The exception thrown is the ArrayIndexOutOfBoundsException .
💡Key Conceptual Anchor:Array
Question 14 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the value of a[1] after the following code is executed? int[] a = {0, 2, 4, 1, 3}; for(int i = 0; i < a.length; i++) a[i] = a[(a[i] + 3) % a.length];
Correct Answer: Option B — 1
Detailed Academic Explanation:
Here's an explanation of the code: 1. The array a is initialized with values: {0, 2, 4, 1, 3}. 2. The for loop iterates over each element of the array using the variable i . 3. Inside the loop, the value of a[i] is updated using the expression a[(a[i] + 3) % a.length] . (i) For i = 0 , a[i] is 0. So, a[(0 + 3) % 5] becomes a[3 % 5] which is a[3] (value 1). (ii) For i = 1 , a[i] is 2. So, a[(2 + 3) % 5] becomes a[5 % 5] which is a[0] (value 0). (iii) For i = 2 , a[i] is 4. So, a[(4 + 3) % 5] becomes a[7 % 5] which is a[2] (value 4). (iv) For i = 3 , a[i] is 1. So, a[(1 + 3) % 5] becomes a[4 % 5] which is a[4] (value 3). (v) For i = 4 , a[i] is 3. So, a[(3 + 3) % 5] becomes a[6 % 5] which is a[1] (value 2). 4. After the loop finishes, the modified array a becomes {0, 1, 4, 3, 2}. 5. Finally, the code prints the value of a[1] using System.out.println(a[1]) , which outputs 1 . Therefore, the output of the code is 1 .
💡Key Conceptual Anchor:Array
Question 15 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Predict the output: public class Test{ public static void main(String... args){ int[] index = new int[5]; System.out.println(index instanceof Object); } }
Correct Answer: Option A — true
Detailed Academic Explanation:
An array is always an instance of Object.
💡Key Conceptual Anchor:Array
Question 16 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
In Java, arrays are objects of which class?
Correct Answer: Option D — None of the above
Detailed Academic Explanation:
None of the above is the correct answer to “In Java, arrays are objects of which class”. This question is standard in competitive examination syllabi for Array.
💡Key Conceptual Anchor:Array
Question 17 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the default initial value of numeric elements in an array of type int in Java?
Correct Answer: Option A — 0
Detailed Academic Explanation:
0 is the correct answer to “What is the default initial value of numeric elements in an array of type int in Java”. This question is standard in competitive examination syllabi for Array.
💡Key Conceptual Anchor:Array
Question 18 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the correct way to initialize a two-dimensional array in Java?
int[][] myArray = {{1, 2}, {3, 4}} is the correct answer to “What is the correct way to initialize a two-dimensional array in Java”. This question is standard in competitive examination syllabi for Array.
💡Key Conceptual Anchor:Array
Question 19 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What does the length attribute of an array in Java represent?
Correct Answer: Option A — The number of elements in the array
Detailed Academic Explanation:
The number of elements in the array is the correct answer to “What does the length attribute of an array in Java represent”. This question is standard in competitive examination syllabi for Array.
💡Key Conceptual Anchor:Array
Question 20 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
How do you access an element in a one-dimensional array named myArray at index 3 in Java?
Correct Answer: Option A — myArray[3]
Detailed Academic Explanation:
myArray[3] is the correct answer to “How do you access an element in a one-dimensional array named myArray at index 3 in Java”. This question is standard in competitive examination syllabi for Array.
💡Key Conceptual Anchor:Array
Question 21 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What happens if you try to access an array element at an index that is out of bounds in Java?
Correct Answer: Option B — It throws an ArrayIndexOutOfBoundsException.
Detailed Academic Explanation:
It throws an ArrayIndexOutOfBoundsException. is the correct answer to “What happens if you try to access an array element at an index that is out of bounds in Java”. This question is standard in competitive examination syllabi for Array.
💡Key Conceptual Anchor:Array
Question 22 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which method is used to find the length of an array in Java?
Correct Answer: Option D — length
Detailed Academic Explanation:
length is the correct answer to “Which method is used to find the length of an array in Java”. This question is standard in competitive examination syllabi for Array.
💡Key Conceptual Anchor:Array
Question 23 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the highest index of an array with 10 elements in Java?
Correct Answer: Option A — 9
Detailed Academic Explanation:
9 is the correct answer to “What is the highest index of an array with 10 elements in Java”. This question is standard in competitive examination syllabi for Array.
💡Key Conceptual Anchor:Array
Question 24 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
How do you find the number of rows in a two-dimensional array named matrix in Java?
Correct Answer: Option C — matrix.length
Detailed Academic Explanation:
matrix.length is the correct answer to “How do you find the number of rows in a two-dimensional array named matrix in Java”. This question is standard in competitive examination syllabi for Array.
💡Key Conceptual Anchor:Array
Question 25 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the default initial value of elements in an array of type boolean in Java?
Correct Answer: Option B — FALSE
Detailed Academic Explanation:
FALSE is the correct answer to “What is the default initial value of elements in an array of type boolean in Java”. This question is standard in competitive examination syllabi for Array.
💡Key Conceptual Anchor:Array
Question 26 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the correct way to copy the elements of one array to another in Java?
Correct Answer: Option A — Use a for loop to iterate through the elements and copy them one by one.
Detailed Academic Explanation:
Use a for loop to iterate through the elements and copy them one by one. is the correct answer to “What is the correct way to copy the elements of one array to another in Java”. This question is standard in competitive examination syllabi for Array.
💡Key Conceptual Anchor:Array
Question 27 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
How do you declare and initialize an array of integers with 5 elements in Java?
Correct Answer: Option A — int[] numbers = new int[5]
Detailed Academic Explanation:
int[] numbers = new int[5] is the correct answer to “How do you declare and initialize an array of integers with 5 elements in Java”. This question is standard in competitive examination syllabi for Array.
💡Key Conceptual Anchor:Array
Question 28 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
How do you declare a dynamic array (ArrayList) of integers in Java?
Correct Answer: Option B — ArrayList numbers[] = new ArrayList[5]
Detailed Academic Explanation:
ArrayList numbers[] = new ArrayList[5] is the correct answer to “How do you declare a dynamic array (ArrayList) of integers in Java”. This question is standard in competitive examination syllabi for Array.
💡Key Conceptual Anchor:Array
Question 29 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the purpose of the System.arraycopy() method in Java?
Correct Answer: Option A — To copy elements from one array to another.
Detailed Academic Explanation:
To copy elements from one array to another. is the correct answer to “What is the purpose of the System.arraycopy() method in Java”. This question is standard in competitive examination syllabi for Array.
💡Key Conceptual Anchor:Array
Question 30 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which of the following is true about the size of an ArrayList in Java?
Correct Answer: Option C — The size can change dynamically.
Detailed Academic Explanation:
The size can change dynamically. is the correct answer to “Which of the following is true about the size of an ArrayList in Java”. This question is standard in competitive examination syllabi for Array.
💡Key Conceptual Anchor:Array
Question 31 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
In Java, how do you remove an element at a specific index from an ArrayList named list?
Correct Answer: Option A — list.remove(index)
Detailed Academic Explanation:
list.remove(index) is the correct answer to “In Java, how do you remove an element at a specific index from an ArrayList named list”. This question is standard in competitive examination syllabi for Array.
💡Key Conceptual Anchor:Array
Question 32 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
How do you check if an element exists in an array or ArrayList in Java?
Correct Answer: Option C — Use the contains() method.
Detailed Academic Explanation:
Use the contains() method. is the correct answer to “How do you check if an element exists in an array or ArrayList in Java”. This question is standard in competitive examination syllabi for Array.
💡Key Conceptual Anchor:Array
Question 33 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the purpose of the Arrays.sort() method in Java?
Correct Answer: Option C — To sort the elements of an array.
Detailed Academic Explanation:
To sort the elements of an array. is the correct answer to “What is the purpose of the Arrays.sort() method in Java”. This question is standard in competitive examination syllabi for Array.
💡Key Conceptual Anchor:Array
Question 34 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
How do you find the index of an element in an ArrayList named list in Java?
Correct Answer: Option B — list.indexOf(element)
Detailed Academic Explanation:
list.indexOf(element) is the correct answer to “How do you find the index of an element in an ArrayList named list in Java”. This question is standard in competitive examination syllabi for Array.
💡Key Conceptual Anchor:Array
Question 35 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which method is used to add an element to the end of an ArrayList in Java?
Correct Answer: Option D — add()
Detailed Academic Explanation:
add() is the correct answer to “Which method is used to add an element to the end of an ArrayList in Java”. This question is standard in competitive examination syllabi for Array.
💡Key Conceptual Anchor:Array
Question 36 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What happens when you try to access an element at an index that is out of bounds in an ArrayList in Java?
Correct Answer: Option B — It throws an ArrayIndexOutOfBoundsException.
Detailed Academic Explanation:
It throws an ArrayIndexOutOfBoundsException. is the correct answer to “What happens when you try to access an element at an index that is out of bounds in an ArrayList in Java”. This question is standard in competitive examination syllabi for Array.
💡Key Conceptual Anchor:Array
Question 37 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which method is used to remove all elements from an ArrayList in Java?
Correct Answer: Option B — clear()
Detailed Academic Explanation:
clear() is the correct answer to “Which method is used to remove all elements from an ArrayList in Java”. This question is standard in competitive examination syllabi for Array.
💡Key Conceptual Anchor:Array
Question 38 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
In Java, how do you find the maximum element in an array?
Correct Answer: Option A — Use a loop to compare each element with the maximum value found so far.
Detailed Academic Explanation:
Use a loop to compare each element with the maximum value found so far. is the correct answer to “In Java, how do you find the maximum element in an array”. This question is standard in competitive examination syllabi for Array.
💡Key Conceptual Anchor:Array
Question 39 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which of the following statements is true about ArrayLists in Java?
Correct Answer: Option B — ArrayLists can have duplicate elements.
Detailed Academic Explanation:
ArrayLists can have duplicate elements. is the correct answer to “Which of the following statements is true about ArrayLists in Java”. This question is standard in competitive examination syllabi for Array.
💡Key Conceptual Anchor:Array
Question 40 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
How do you declare a multi-dimensional array in Java?
Correct Answer: Option D — All of the above
Detailed Academic Explanation:
All of the above is the correct answer to “How do you declare a multi-dimensional array in Java”. This question is standard in competitive examination syllabi for Array.
💡Key Conceptual Anchor:Array
✓Link copied to clipboard
Continue Your Practice
Advance Html — Part 1
Master the next curriculum module with 40 exam-standard MCQs.
💡Examiner's Advisory for Programming & Software Development
In competitive commission exams (FPSC, PPSC, KPPSC, SPSC, CSS, PMS), questions are frequently phrased with distractor options designed to catch rote learners. Whenever you answer an MCQ, read the Detailed Academic Explanation and Conceptual Anchor to understand why the remaining options are incorrect.