Font size
WorksheetsPractice <ultiple Choice - APCSA
Total questions: 18
Worksheet time: 41mins
Which of the following will create an out of bounds error? (select 2)
int sum1 = 100 + 50;
int sum2 = sum1 + 250;
int sum3 = sum2 + sum2;
System.out.println(sum3);
What will be the final output?
950
800
sum2sum2
sum1250
String s1 = "goat";
String s2 = s1.substring(0,s1.length());
boolean z = s1.equals(s2);
What is the value of z?
true
false
This code will not compile.
StringIndexOutOfBoundsException
In total, how many times is the inner loop executed?
5
10
15
50
Infinite Loop
What does the following code print?
5 6 7 8 9
4 5 6 7 8 9 10 11 12
3 5 7 9 11
3 4 5 6 7 8 9 10 11 12
What number is at index 6?
(a)
What is the value of nums[4] after this code is executed?
4
44
40
10
What is the result of this code executing?
nums[1] and nums[2] will both have the original nums[2] value.
nums[1] and nums[2] will both have the original nums[1] value.
nums[2] and nums[1] swap values.
nothing changes
What is printed?
ArrayList<Double> vals;
vals = new ArrayList<Double>();
vals.add(3.5);
vals.add(4.5);
vals.add(5.5);
vals.set(0, 2.5) ;
System.out.println(vals);
[2.5, 4.5, 5.5, 3.5]
[2.5, 3.5, 4.5, 5.5]
[3.5, 4.5, 5.5, 2.5]
[2.5, 4.5, 5.5]
What will be the value in variable x after this code segment is executed?
double x = (double) 5 / (int) 2
2
2.5
There will be a runtime error
There will be a syntax error
2.0
What keyword is used to inherit a class in Java?
extends
implements
inherits
uses
Which of the following pairs of declarations will cause an error message?
I. double x = 14.7;
int y = x;
II. double x = 14.7;
int y = (int) x;
III. int x = 14;
double y = x;
None
I only
II only
III only
I and III only
Which of the following will evaluate to true only if boolean expressions
A, B, and C are all false?
!A && !(B && !C)
!A || !B || !C
!(A || B || C)
!(A && B && C)
!A || !(B || !C)
What will be the output of this code segment?
Which of the following statements correctly declares a two-dimensional integer array?
int Matrix[ ] = new int[5,4];
int Matrix[ ]; Matrix = new int[5,4];
int Matrix[ ][ ] = new int[5][4];
int Matrix[ ][ ] = int[5][4];
Given the code, what is the value of things.length ?
4
3
12
7
Given the code, what is in values[2][1] ?
7.9
9.2
7.3
0.5
How many times will "Hi" be printed?
7
6
16
8
