wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Practice <ultiple Choice - APCSA

Total questions: 18

Worksheet time: 41mins

Name
Class
Date
1.

Which of the following will create an out of bounds error? (select 2)

a)
b)
c)
d)
2.

int sum1 = 100 + 50;

int sum2 = sum1 + 250;

int sum3 = sum2 + sum2;

System.out.println(sum3);


What will be the final output?

a)

950

b)

800

c)

sum2sum2

d)

sum1250

3.

String s1 = "goat";

String s2 = s1.substring(0,s1.length());

boolean z = s1.equals(s2);


What is the value of z?

a)

true

b)

false

c)

This code will not compile.

d)

StringIndexOutOfBoundsException

4.

In total, how many times is the inner loop executed?

a)

5

b)

10

c)

15

d)

50

e)

Infinite Loop

5.

What does the following code print?

a)

5 6 7 8 9

b)

4 5 6 7 8 9 10 11 12

c)

3 5 7 9 11

d)

3 4 5 6 7 8 9 10 11 12

6.

What number is at index 6?

(a)  

7.

What is the value of nums[4] after this code is executed?

a)

4

b)

44

c)

40

d)

10

8.

What is the result of this code executing?

a)

nums[1] and nums[2] will both have the original nums[2] value.

b)

nums[1] and nums[2] will both have the original nums[1] value.

c)

nums[2] and nums[1] swap values.

d)

nothing changes

9.

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);

a)

[2.5, 4.5, 5.5, 3.5]

b)

[2.5, 3.5, 4.5, 5.5]

c)

[3.5, 4.5, 5.5, 2.5]

d)

[2.5, 4.5, 5.5]

10.

What will be the value in variable x after this code segment is executed?

double x = (double) 5 / (int) 2

a)

2

b)

2.5

c)

There will be a runtime error

d)

There will be a syntax error

e)

2.0

11.

What keyword is used to inherit a class in Java?

a)

extends

b)

implements

c)

inherits

d)

uses

12.

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;

a)

None

b)

I only

c)

II only

d)

III only

e)

I and III only

13.

Which of the following will evaluate to true only if boolean expressions

A, B, and C are all false?

a)

!A && !(B && !C)

b)

!A || !B || !C

c)

!(A || B || C)

d)

!(A && B && C)

e)

!A || !(B || !C)

14.

What will be the output of this code segment?

a)
The program will output 'category 1'
b)
The program will output 'category 2'
c)
The program will not output anything
d)
The program will output 'Mike'
15.

Which of the following statements correctly declares a two-dimensional integer array?

a)

int Matrix[ ] = new int[5,4];

b)

int Matrix[ ]; Matrix = new int[5,4];

c)

int Matrix[ ][ ] = new int[5][4];

d)

int Matrix[ ][ ] = int[5][4];

16.

Given the code, what is the value of things.length ?

a)

4

b)

3

c)

12

d)

7

17.

Given the code, what is in values[2][1] ?

a)

7.9

b)

9.2

c)

7.3

d)

0.5

18.

How many times will "Hi" be printed?

a)

7

b)

6

c)

16

d)

8