0%
0 / 2 answered
Run Time Errors Practice Test
•2 QuestionsQuestion
1 / 2
Q1
Consider the following code:
Object[] objects = new Object<u>20</u>;
for(int i = 0; i < objects.length; i++) {
switch(i % 4) {
case 0:
objects<u>i</u> = new Integer(i + 3);
break;
case 1:
objects<u>i</u> = "This val: " + i;
break;
case 2:
objects<u>i</u> = new Double(i * 4.4);
break;
case 3:
objects<u>i</u> = "That val: " + (i*12);
break;
}
}
String s = (String)objects<u>8</u>;
System.out.println(s);
What is the error in the code above?
Consider the following code:
Object[] objects = new Object<u>20</u>;
for(int i = 0; i < objects.length; i++) {
switch(i % 4) {
case 0:
objects<u>i</u> = new Integer(i + 3);
break;
case 1:
objects<u>i</u> = "This val: " + i;
break;
case 2:
objects<u>i</u> = new Double(i * 4.4);
break;
case 3:
objects<u>i</u> = "That val: " + (i*12);
break;
}
}
String s = (String)objects<u>8</u>;
System.out.println(s);
What is the error in the code above?