Array Examples & Exceptions QuizJ8 Home « Array Examples & Exceptions Quiz

Java Objects & Classes Quiz 2

The quiz below tests your knowledge of the material learnt in Objects & Classes - Lesson 2 - Array Examples & Exceptions.

Question 1 : What are multi dimensional arrays with an uneven number of elements in each row or column known as?
- Multi dimensional arrays with an uneven number of elements in each row or column are known as irregular arrays.
Question 2 : What will be output from this code snippet?

String strArray[] = {"one", "aa", "c", "rt", "je"};
System.out.println(strArray[5]);
- The code snippet will throw an <code>ArrayIndexOutOfBoundsException</code> exception when run.
Question 3 : An array index starts from 1?
- An array index starts from 0.
Question 4 : What array property is used with the for conditional statement to loop through an array?
- The <code>length</code> array property is used with the <code>for</code> conditional statement to loop through an array.
Question 5 : What will be output from this code snippet?

Number[] anArray = new Float[1];
anArray[0] = new Integer(1);
System.out.println(anArray[0]);
- The code snippet will throw an <code>ArrayStoreException</code> exception as <code>Integer</code> is an invalid type for this <code>Float</code> type array.
Question 6 : We can only store primitive types in an array?
- We can store primitive and reference types in an array.
Question 7 : What will be output from this code snippet?

int anArray[];
anArray = new int[-2];
anArray[0] = 672;
System.out.println(anArray[0]);
- The code snippet will throw a <code>NegativeArraySizeException</code> exception as we can't access an array with a negative array allocation.
Question 8 : What are multi dimensional arrays with the same number of elements in each row or column known as?
- Multi dimensional arrays with the same number of elements in each row or column are known as regular arrays.
Quiz Progress Bar Please select an answer


What's Next?

The next quiz on Java Objects & Classes is all about class structure and syntax.