Arrays QuizS2C Home « Objects & Classes Quiz

The questions in this Java quiz are on the topics covered in the java - Objects & Classes section of the site. The table below lists the lesson used for each quiz, a description of the lesson content and the quiz number and questions associated with that lesson.

Lesson Summary

Click on a lesson in the table to go to that lesson for a refresher on the topics for that quiz.

Click on a quiz in the table to go straight to the quiz for a particular lesson.

Objects & Classes Lessons Description Quiz Info.
Lesson 1 - ArraysIn this lesson we look at arrays and how to use them in java.This quiz.
8 questions
Lesson 2 - Class Structure & SyntaxFor this lesson we looked at class structure and syntax within our Java programs.Quiz2
8 questions
Lesson 3 - Reference VariablesThis lesson is about reference variables and how to use them within our Java programs.Quiz3
7 questions
Lesson 4 - MethodsWe have used methods throughout the lessons so far so its time for a thorough investigation of what we can do with these members.Quiz4
10 questions
Lesson 5 - Instance Variables & ScopeThis lesson is about instance variables, how to use them and their scope.Quiz5
6 questions
Lesson 6 - ConstructorsIn this lesson we learn about constructors, which we can use to instantiate objects of our classes.Quiz6
7 questions
Lesson 7 - Static MembersFor this lesson we investigate what static means and how to apply it to our class members.Quiz7
6 questions
Lesson 8 - EnumerationsIn our final lesson of this section we go through enumerations which were introduced in java.Quiz8
8 questions

Java Objects & Classes Quiz 1

The quiz below tests your knowledge of the material learnt in Objects & Classes - Lesson 1 - Arrays.

Question 1 : What is the second step of array creation?
- Array allocation is the second step of creating an array.
Question 2 : We can look at an element of an array after array declaration?
- We can only look at an element within an array after allocation. After declaration no size has been allocated.
Question 3 : What will be output from this code snippet?

String strArray[] = {"one", "aa", "c", "rt", "je"};
System.out.println(strArray[1]);
- The output will be <code>aa</code>. Arrays are zero-index based
Question 4 : What will be output from this code snippet?

String strArray3[] = new String[3]{"one", "rt", "je"};
System.out.println(strArray3[1]);
- The code doesn't compile. When using a single statement to create an array, no size should be specified.
Question 5 : Which of the following statements will compile?

int intArray1[][]; // A
int[][] intArray2; // B
int[] intArray3[]; // C
- All the statements will compile as the square brackets can follow the type, the array name or be split between the two for multi dimensional arrays.
Question 6 : What will be output from this code snippet?

String[] strArray1;; // Array declaration
strArray1 = new String[1]; // Array allocation
System.out.println(strArray1[0]);
- The output will be <code>null</code> as space has been allocated so array is initialized to default.
Question 7 : We can have a maximum of two dimensions for arrays?
- There is actually no limit to the amount of dimensions an array can have although in practical terms arrays are rarely more than three dimensions.
Question 8 : What will be result when this code snippet is run?

int intArray1[]; // 1
intArray1 = int[2]; // 2
intArray1[0] = 22; // 3
intArray1[1] = 44; // 4
System.out.println(intArray1[0]); // 5
- Doesn't compile. The <code>new</code> keyword is mandatory for multiple statement array creation.<br>The code would compile and output <code>22</code> if line 2 changed to <code>intArray1 = new int[2];</code>.
Quiz Progress Bar Please select an answer

What's Next?

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