0% found this document useful (0 votes)
44 views3 pages

Array

Uploaded by

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

Array

Uploaded by

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

[Link] 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

Answer:b)A collection of elements with the same type

[Link] 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
Answer:a)0 to length - 1

[Link] 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
Answer:b)By using the element's index

[Link] 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
Answer:a)A runtime exception is thrown

[Link] of the following is used to declare,construct, and initlaize an array?


A. int arr [] [] = {1, 2, 3, 4};
B. int [] arr = (1, 2, 3);
C. int [] arr = {};
D. int arr [] = {1, 2, 3};
Answer:D)int arr [] = {1, 2, 3};

[Link] in array start with ______.


A. -1
B. 0
C. 1
D. infinite
Answer:B)0

[Link] can calculate the length of an array using ________.


A. sizeof(array)
B. [Link]
C. [Link]
D. [Link]()
Answer:C)[Link]

[Link] of the following is advantage of java array?


A. Code Optimization
B. Random access
C. Size No-Limit
D. Both A and B
Answer:D)Both A and B

[Link] java, array elements are stored in ________ memory locations.


A. Random
B. Sequential
C. Sequential & Random
D. Binary search
Answer:B)Sequential

[Link] will be output for the following code?


class Main
{
public static void main(String args[])
{
int arr[] = new int[] {0 , 1, 2, 3, 4, 5, 6, 7, 8, 9};
int n = 6;
n = arr[arr[n] / 2];
[Link](n);
}}
A. 3
B. 0
C. 6
D. 1
Answer:A)3

[Link] is the type of variable "b" and "d" in the below snippet?
int a[], b;
int []c, d;
A. "b" and "d" are int
B. "b" and "d" are arrays of type int
C. "d" is int variable; and "b" is int array
D. "b" is int variable; and "d" is int array
Answer: D
Explanation: If [] is declared after variable it is applicable only to one
variable.
If [] is declared before variable it is applicable to all the variables.

[Link] 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.
Answer:a) An array expands automatically when it is full.

[Link] will be output for the following code?


class Test
{
public static void main (String[] args)
{
int arr1[] = {1, 2, 3};
int arr2[] = {1, 2, 3};
if ([Link](arr2))
[Link]("Same");
else
[Link]("Not same");
}
}
a)Same
b)Not same
Answer:b)Not same([Link](arr2) is same as (arr1 == arr2))

[Link] in java are-


a)object references
b)objects
c) primitive data type
d)None
Answer:b)objects

[Link] numbers of a dimensional array are also known as:


a)packets
b)blocks
c)subscripts
d)compartments
Answer:c)subscripts

You might also like