Test: Computer Science

Consider the following code:

Object[] objects = new Object[20];

for(int i = 0; i < objects.length; i++) {

     switch(i % 4) {

     case 0:

          objects[i] = new Integer(i + 3);


     case 1:

          objects[i] = "This val: " + i;


     case 2:

          objects[i] = new Double(i * 4.4);


     case 3:

          objects[i] = "That val: " + (i*12);




String s = (String)objects[8];



What is the error in the code above?

There are no errors.

There will be a NullPointerException.

There is an array overrun.

You cannot assign various types to the array in that manner.

There will be a ClassCastException thrown.

1/2 questions


Access results and powerful study features!

Take 15 seconds to create an account.
Start now! Create your free account and get access to features like:
  • Full length diagnostic tests
  • Invite your friends
  • Access hundreds of practice tests
  • Monitor your progress over time
  • Manage your tests and results
  • Monitor the progress of your class & students
By clicking Create Account you agree that you are at least 13 years old and you agree to the Varsity Tutors LLC Terms of Use and Privacy Policy.
Learning Tools by Varsity Tutors