Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

java datatype

Total questions: 14

Worksheet time: 8mins

Name
Class
Date
1.

Which three are legal array declarations?

a)

2, 3, 4

b)

2, 4, 5

c)

1, 2, 4

d)

All are correct.

2.

Which will legally declare, construct, and initialize an array?

a)

int [] myList = {"1", "2", "3"};

b)

int [] myList = (5, 8, 2);

c)

int myList [] [] = {4,9,7,0};

d)

int myList [] = {4, 3, 7};

3.

Which four options describe the correct default values for array elements of the types indicated?

a)

1, 2, 3, 4

b)

1, 3, 4, 5

c)

2, 4, 5, 6

d)

3, 4, 5, 6

4.

What is the numerical range of a char?

a)

-128 to 127

b)

-(215) to (215) - 1

c)

0 to 32767

d)

0 to 65535

5.

What will be the output of the program?

a)

small

b)

huge

c)

tiny

d)

Compilation fails

6.

Which expression evaluates to false?

a)

15 % 3 < 2

b)

3 * 3 % 2 <= 0

c)

false == false

d)

false == false == false == false

7.

Which expression evaluates to true?

a)

false == false

b)

true != true

c)

4 < 4

d)

true == true != true

8.

How would you declare a variable that tells you that someone passed a class?

a)

boolean passed = 'true';

b)

boolean passed = true;

c)

passed = true;

d)

String passed = "true";

9.

How would you declare a variable storing the tax rate?

a)

int taxRate = 5.1;

b)

taxRate = "5.1";

c)

double taxRate = 5.1;

d)

double taxRate = "5.1";

10.

What data type would you use for storing the number of students in a class?

a)

boolean

b)

String

c)

double

d)

int

11.

Name the data type: '3'

a)

int

b)

char

c)

String

d)

None of the above

12.

Which declaration with throw an error?

a)

String name = "1 1233 141";

b)

double num = 1;

c)

int bigNumber = 1234567890;

d)

char random = '7';

13.

Which declaration will throw an error?

a)

double num = 8;

b)

int averageGrade = 89.7;

c)

boolean done = false;

d)

String done = "true";

14.

What prints out "I love Java" successfully?

a)

System.out.println(I love Java);

b)

Systemoutprintln("I love Java);

c)

System.out.println("I love" + " Java");

d)

System.out.println("I love Java")