wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

AP CSA Variables and Operators

Total questions: 14

Worksheet time: 7mins

Name
Class
Date
1.

Which variable type is NOT a primitive variable type?

a)

boolean

b)

String

c)

int

d)

double

2.

What is a logic error?

a)

An mistyped statement that causes the compiler to throw an exception.

b)

An illegal operation that causes the compiler to throw an exception.

c)

An illegal operation that causes the program to have a run-time error.

d)

An error a programmer makes that causes the program to behave differently than expected.

3.

What is the correct syntax to instantiate a Finch object with its default constructor?

a)

Finch(f);

b)

Finch f;

c)

Finch f = Finch();

d)

Finch f = new Finch();

4.

What is the result of 3/2 in Java?

a)

1.5

b)

1.0

c)

1

d)

0

5.

What is the result of 3.0/2 in Java?

a)

1.5

b)

1.0

c)

1

d)

0

6.

What is the % operator in Java?

a)

percentage

b)

homonculus

c)

modulus

d)

modulator

7.

What is the result of 3%2?

a)

1

b)

1.5

c)

1.0

d)

0

8.

What is the result of 2%1?

a)

0

b)

1

c)

2

d)

This cannot be calculated.

9.

What is the difference between primitive variables and Object reference variables?

a)

Primitive variables hold a variable's value, whereas Object reference variables do not a value, they point to it .

b)

Primitive variables take up a specific amount of memory, whereas the amount of memory an Object reference can take up varies.

c)

Both answers are correct.

10.

What is the long form of x++?

a)

x += x;

b)

x = x + 1;

c)

x + 1;

d)

y = x + 1;

11.

What is the long form of x--?

a)

z = x - y;

b)

x - 1;

c)

x -= x;

d)

x = x - 1;

12.

What is the long form of x+=5?

a)

x = 5;

b)

x = + 5;

c)

x = x + 5;

d)

y = x + 5;

13.

Where does modulus fall within the PEMDAS order of operations?

a)

After multiplication and division

b)

Before multiplication and division

c)

At the same level of multiplication and division

d)

Whenever you feel like it.

14.

Which statement is an incorrect attempt at instantiating a String object?

a)

new String("hi!");

b)

String s = new String("hi!");

c)

String s = "hi!";

d)

String s = String("hi!");