adplus-dvertising
frame-decoration

Question

What is the output of the following piece of code?
public class array
{
public static void main(String args[])
{
int []arr = {1,2,3,4,5};
System.out.println(arr[5]);
}
}

a.

4

b.

5

c.

ArrayIndexOutOfBoundsException

d.

InavlidInputException

Answer: (c).ArrayIndexOutOfBoundsException

Engage with the Community - Add Your Comment

Confused About the Answer? Ask for Details Here.

Know the Explanation? Add it Here.

Q. What is the output of the following piece of code?

Similar Questions

Discover Related MCQs

Q. Consider an array A[20, 10], assume 4 words per memory cell and the base address of array A is 100. What is the address of A[11, 5] ? Assume row major storage.

Q. Which of these best describes an array?

Q. A program P reads in 500 integers in the range [0..100] exepresenting the scores of 500 students. It then prints the frequency of each score above 50. What would be the best way for P to store the frequencies?

Q. Matrix A when multiplied with Matrix C gives the Identity matrix I, what is C?

Q. What is the disadvantage of matrices?

Q. Which of the following are the uses of matrices?

Q. If column-major order is used, how is the following matrix stored in memory?
a b c

d e f

g h i

Q. If row-major order is used, how is the following matrix stored in memory?
a b c

d e f

g h i

Q. How do you allocate a matrix using a single pointer in C?(r and c are the number of rows and columns respectively)

Q. Which of the following property does not hold for matrix multiplication?

Q. What is the order of a matrix?

Q. What are the advantages of sparse matrices over normal matrices?

Q. What is sparsity of a matrix?

Q. Suppose the contents of an array A are, A = {1, null, null, null, null, 10};
What would be the size of the array considering it as a normal array and a sparse array?

Q. What is the difference between a normal(naive) array and a sparse array?

Q. When do you use a sparse array?

Q. What is a sparse array?

Q. What is the worst case time complexity of inserting an element into the sorted array?

Q. What are some of the applications of sorted arrays?

Q. To search for an element in a sorted array, which searching technique can be used?