0% found this document useful (0 votes)
39 views6 pages

MCQ On ARRAY With Answers

Uploaded by

ishanbrave2007
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views6 pages

MCQ On ARRAY With Answers

Uploaded by

ishanbrave2007
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Arrays

Multiple choice questions 9. How do we describe an array in the best way?


(a) The Array shows a hierarchical structure.
1. Special symbols used to declare an array in Java (b) Arrays are immutable.
is : (c) Container that stores the elements of similar
(a) Braces { } types
(b) Parentheses () (d) The Array is not a data structure
(c) Square Brackets [ ] 10. Choose the correct way of declaring an array :
(d) Angled Brackets < > (a) int javatpoint[10];
2. The special symbols used to initialize an array at (b) int javatpoint;
the time of the declaration itself is : (c) javatpoint{20};
(a) Parentheses ( ) (d) array javatpoint[10];
(b) Square Brackets [ ] 11. How to initialize an array in JAVA language?
(c) Braces { } (a) int arr[2]=(10, 20)
(d) Angled Brackets < > (b) int arr(2)={10, 20}
3. We can skip initializing some elements of the (c) int arr[2] = {10, 20}
array during Shorthand Initialization. (TRUE / (d) int arr(2) = (10, 20)
FALSE) 12. Identify the advantage of the array from the given
(a) FALSE (b) TRUE options
4. We can declare an array without initialization and (a) Elements of mixed data types can be stored.
without mentioning the size. (TRUE / FALSE) (b) Easier to access the elements in an array
(a) TRUE (b) FALSE (c) Index of the first element starts from 1.
5. Default value of an element of Object type array (d) Elements of an array cannot be sorted
is : 13. What is the highly used concept of an array?
(a) 0 (b) null (a) Binary Search tree
(c) -1 (d) Garbage value (b) Caching
6. Default value of byte, short, int or long data type (c) Spatial locality
elements of an array in Java. (d) Scheduling of Processes
(a) -1 (b) 1 14. The disadvantage of the array is :
(c) 0 (d) Garbage value (a) 
Stack and Queue data structures can be
7. Identify the default value of float or double data implemented through an array.
type elements of an array in Java (b) Index of the first element in an array can be
(a) 0 (b) 0.0 negative
(c) 1 (d) 1.0 (c) Wastage of memory if the elements inserted in
an array are lesser than the allocated size
8. What will be the default value of a char data type
elements of an array in Java? (d) Elements can be accessed sequentially.

(a) ‘A’ (b) ‘\0’ 15. What is the size of int arr[9] assuming that int is of
4 bytes?
(c) null (d) ‘\0’ or null
(a) 9 (b) 36 24. Array A[ index] = ___( first element in an array) ?
(c) 35 (d) None of the above (a) 0 (b) -1
16. Name the process of inserting an element in the (c) 2 (d) 1
stack? 25. Identify an element in an array which a user can
(a) Insert (b) Add access.
(c) Push (d) None of the above (a) randomly (b) sequentially
17. Name the condition when the user tries to delete (c) exponentially (d) logarithmically
the element from the empty stack ? 26. How can we define an array in java?
(a) Underflow (a) objects
(b) Garbage collection (b) object references
(c) Overflow (c) primitive data type
(d) None of the above (d) none of above
18. Name the condition where the size of the stack is 27. When we pass an array to a method, a method
10 and we try to add the 11th element in the stack. receives ____
(a) Underflow (a) A copy of the array
(b) Garbage collection (b) a copy of the forst element
(c) Overflow (c) the reference of the array
(d) None of the above (d) the length of the array
19. At which time the 28. Name the operators that is used to allocate
ArrayIndexOutOfBoundsException occur? memory to array variable in Java?
(a) Compile-time (a) malloc (b) alloc
(b) Run-time (c) new (d) new malloc
(c) Not an error 29. Choose the incorrect Statement
(d) Not an exception at all (a) It is necessary to use new operator to initialize
20. Which concepts make extensive use of arrays? an array
(a) Binary trees (b) 
Array can be initialized using comma
(b) Scheduling of processes separated expressions surrounded by curly
(c) Caching braces
(d) Spatial locality (c) 
Array can be initialized when they are
declared
21. Choose the best reason to use arrays.
(d) None of the mentioned
(a) Objects of mixed data types can be stored
30. What is needed to specify time of array
(b) Elements in an array cannot be sorted
initialization?
(c) Index of first element of an array is 1
(a) Row
(d) Easier to store elements of same data type
(b) Column
22. Why we should avoid using arrays?
(c) Both Row and Column
(a) Data structure like queue or stack cannot be
(d) None of the mentioned
implemented
(b) There are chances of wastage of memory space
Fill in the blanks
if elements inserted in an array are lesser than
the allocated size 31. Array is a collection of elements of ___ data type.
(c) Index value of an array can be negative (a) Same
(d) Elements are sequentially accessed (b) Different
23. If int is of 4bytes, what is the size of int arr[15];? 32. JVM implements arrays as ___ type.
(a) 15 (b) 19 (a) Primitive
(c) 11 (d) 60 (b) Object
33. Java-Arrays have ___. 3. default value of an (iii) 0
(a) Names element of Object
(b) Values type array
(c) Methods and Fields 4. default value of (iv) null
(d) None byte, short, int or
long data type
34. Array declaration without initialization ___
(a) 1-(ii), 2-(i), 3-(iv), 4-(iii)
memory.
(b) 1-(i), 2-(ii), 3-(iv), 4-(iii)
(a) Does not allocate
(c) 1-(ii), 2-(i), 3-(iii), 4-(iv)
(b) Allocates memory
(d) 1-(ii), 2-(iv), 3-(i), 4-(iii)
35. An array index starts with ___.
42. Match the columns:
(a) –1 (b) 0
Group A Group B
(c) 1 (d) Any integer
1. default value of a (i) stores the
36. Name of an array variable can start with ___.
char data type elements of
(a) A letter similar types
(b) Underscore ( _ ) 2. array (ii) ‘\0’ or null
(c) Dollar Symbol ($) 3. declaring an array (iii) int arr[2] = {10, 20}
(d) All 4. initialize an array (iv) int javatpoint[10];
37. Array of arrays is called ___ array. (a) 1-(ii), 2-(i), 3-(iv), 4-(iii)
(a) Bidirectional (b) 1-(i), 2-(ii), 3-(iv), 4-(iii)
(b) Combo (c) 1-(ii), 2-(i), 3-(iii), 4-(iv)
(c) Multidimensional (d) 1-(ii), 2-(iv), 3-(i), 4-(iii)
(d) Multi-value 43. Match the columns:
38. Array of dimension N contains __ number of Group A Group B
subscripts or brackets? 1. Advantage of the (i) Spatial locality
(a) N-1 (b) N array
(c) N+1 (d) 10*N 2. Highly uses the (ii) Easier to access
concept of an the elements
39. Row number and Column number in
array
Multidimensional array starts with ___ digit.
3. Disadvantage of (iii) 36
(a) -1 (b) 0
the array
(c) 1 (d) 2 4. Size of int arr[9] (iv) Wastage of
40. 4-dimensional array is an example of ___ memory
dimensional arrays. (a) 1-(ii), 2-(i), 3-(iv), 4-(iii)
(a) 4 (b) 3 (b) 1-(i), 2-(ii), 3-(iv), 4-(iii)
(c) 2 (d) 1 (c) 1-(ii), 2-(i), 3-(iii), 4-(iv)
(d) 1-(ii), 2-(iv), 3-(i), 4-(iii)
Match the following
44. Match the columns:
41. Match the columns: Group A Group B
Group A Group B 1. inserting an (i) Underflow
1. special symbols (i) Braces { } element in the
used to declare an stack
array 2. delete the element (ii) Push
2. to initialize an (ii) Square Brackets from the empty
array [] stack
3. size of the stack (iii) run time 48. Choose the correct output of Java code snippet
is 10 and we try int[] balls = {};
to add the 11th System.out.print(balls.length);
element in the (a) 0 (b) -1
stack (c) 1 (d) Compiler error
4. Array Index (iv) Overflow 49. Choose the correct output of Java program with
Out of Bounds arrays
Exception occur at
String[] colors = {“RED”;”YELLOW”;”WHITE”};
(a) 1-(ii), 2-(i), 3-(iv), 4-(iii)
System.out.print(colors[2]);
(b) 1-(i), 2-(ii), 3-(iv), 4-(iii)
(a) RED
(c) 1-(ii), 2-(i), 3-(iii), 4-(iv)
(b) YELLOW
(d) 1-(ii), 2-(iv), 3-(i), 4-(iii)
(c) WHITE
45. Match the columns:
(d) Compiler error
Group A Group B
50. Choose the correct output of Java program with
1. extensive use of (i) Easier to store arrays
arrays elements
public class Polo {
2. Advantages of (ii) Spatial locality
public static void main(String args[])
arrays
{
3. Disadvantages of (iii) 0
arrays String[] computer = {“RAM”,”HDD”,”MOUSE”};
4. Index of the first (iv) chances of String[] parts = {computer[0],computer[2]};
element in an wastage of System.out.print(parts[1]);
array memory space }
(a) 1-(ii), 2-(i), 3-(iv), 4-(iii) }
(b) 1-(i), 2-(ii), 3-(iv), 4-(iii) (a) RAM (b) HDD
(c) 1-(ii), 2-(i), 3-(iii), 4-(iv) (c) MOUSE (d) Compiler error
(d) 1-(ii), 2-(iv), 3-(i), 4-(iii) 51. Choose the correct output of Java program
int ages[3] = {25, 27, 30};
Programming based questions System.out.println(ages[1]);

46. Choose the correct output for Java code snippet (a) 25 (b) 27
with arrays (c) 30 (d) Compile error
static int[] nums; 52. When index of an element is N, what will be its
public static void main(String args[]) actual position in the array
(a) N-1 (b) N
{
(c) N+1 (d) N+2
System.out.println(nums.length);
53. Choose correct output for the code?
}
#include <stdio.h>
(a) 0 int main()
(b) null {
(c) Compiler error int arr[5]={10,20,30,40,50};
(d) Runtime Exception - Null Pointer Exception system.out.print(“%d”, arr[5]);
47. Choose the correct output of the below Java return 0;
program }
int[] marks = {35,65,95}; (a) Garbage value
System.out.print(marks.length + “,” + marks[1]); (b) 10
(a) 2,65 (b) 3,95 (c) 50
(c) 3,65 (d) Compiler error (d) None of the above
54. With reference to the program code given below, fact=fact*i;
answer the questions that follow: }
public class Prime System.out.println(“Factorial of “+number+” is:
{ “+fact);
public static void main(String args[]) }
{ }
int i,m=0,flag=0; (a) What will be the output?
int n=3;//it is the number to be checked (i) Factorial of 5 is: 120
m=n/2; (ii) Factorial of 5 is: 121

if(n==0||n==1){ (iii) Factorial of 5 is: 122


(iv) Factorial of 5 is: 123

System.out.println(n+” is not a prime
number”); (b) What is the name of the class?
}else{ (i) System.out.println

for(i=2;i<=m;i++){ (ii) static void main()

if(n%i==0){ (iii) Factorial


(iv) Factor

System.out.println(n+” is not a prime
number”); 56. Concerning the program code given below,
answer the questions that follow:
flag=1;
class Palindrome{
break;
public static void main(String args[]){
}
int r,sum=0,temp;
}
int n=454;//It is the number variable to be checked
if(flag==0) {System.out.println(n+” is prime
for palindrome
number”); }
temp=n;
}//end of else
while(n>0){
}
r=n%10; //getting remainder
}
sum=(sum*10)+r;
(a) What will be the output? n=n/10;
(i) 3 is a prime number }
(ii) 2 is a prime number if(temp==sum)
(iii) 4 is a prime number System.out.println(“palindrome number “);
(iv) 5 is a prime number else
(b) What will be the output if the number entered System.out.println(“not palindrome”);
is 45? }
(i) 45 is a prime number }
(ii) It is a prime number (a) What will be the output?
(iii) n is not a prime number (i) palindrome number
(iv) 45 is not a prime number
(ii) not palindrome
55. Concerning the program code given below,
(iii) Palindrome
answer the questions that follow:
(iv) 454
class Factorial{
(b) What is the class Palindrome doing?
public static void main(String args[]){
(i) Checking number is prime or not
int i,fact=1;
int number=5;//It is the number to calculate (ii) arranging number is ascending order
factorial (iii) checking number is Palindrome or not
for(i=1;i<=number;i++){ (iv) none of the above
Answers

Multiple choice questions 32. (b) Object


33. (c) Methods and Fields
1. (c) Square Brackets [ ] 34. (a) Does not allocate
2. (c) Braces { } Explanation: syntax: int[] myArray = {13, 14, 15};
3. (a) FALSE 35. (b) 0
4. (a) TRUE Explanation: The first element of an array is at
5. (b) null index 0 , and the last element is at the index value
6. (c) 0 equal to the value of the array’s length property
7. (b) 0.0 minus 1.
8. (d) ‘\0’ or null 36. (d) All
9. (c) Container that stores the elements of similar 37. (c) Multidimensional
types 38. (b) N
10. (a) int javatpoint[10]; 39. (b) 0
11. (c) int arr[2] = {10, 20} 40. (b) 3
12. (b) Convenient to access the elements in an array
13. (c) Spatial locality Match the following
14. (c) Wastage of memory if the elements inserted in
41. (a) 1-(b), 2-(a), 3-(d), 4-(c)
an array are lesser than the allocated size
42. (a) 1-(b), 2-(a), 3-(d), 4-(c)
15. (b) 36
43. (a) 1-(b), 2-(a), 3-(d), 4-(c)
16. (c) Push
44. (a) 1-(b), 2-(a), 3-(d), 4-(c)
17. (a) Underflow
45. (a) 1-(b), 2-(a), 3-(d), 4-(c)
18. (c) Overflow
19. (b) Run-time
Programming based questions
20. (d) Spatial locality
21. (d) Easier to store elements of same data type 46. (d) Runtime Exception - Null Pointer Exception
22. (b) There are chances of wastage of memory space 47. (c) 3,65
if elements inserted in an array are lesser than 48. (a) 0
the allocated size 49. (d) Compiler error
23. (d) 60
50. (c) MOUSE
24. (a) 0
51. (d) Compile error
25. (a) randomly
52. (c) N+1
26. (a) objects
53. (a) Garbage value
27. (c) the reference of the array
54. (a) (i) 3 is a prime number
28. (c) new
(b) (iv) 45 is not a prime number
29. (a) It is necessary to use new operator to initialize
55. (a) (i) Factorial of 5 is: 120
an array
(b) (iii) Factorial
30. (a) Row
56. (a) (i) palindrome number
Fill in the blanks (b) (iii) checking number is Palindrome or not

31. (a) Same


Explanation: An array in Java is a set of variables
referenced by using a single variable name
combined with an index number.

You might also like