wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Java Basics

Total questions: 25

Worksheet time: 27mins

Name
Class
Date
1.

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

2.

Which one of these lists contains only Java programming language keywords?

a)

class, if, void, long, Int, continue

b)

try, virtual, throw, final, volatile, transient

c)

goto, instanceof, native, finally, default, throws

d)

strictfp, constant, super, implements, do

e)

byte, break, assert, switch, include

3.

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

4.

Which is a valid keyword in java?

a)

interface

b)

string

c)

Float

d)

unsigned

5.

Which three are legal array declarations?

a)

2, 3, 4

b)

2, 4, 5

c)

1, 2, 4

d)

All are correct.

6.

Which three are valid declarations of a float?

a)

1, 2, 4

b)

2, 3, 5

c)

1, 3, 6

d)

2, 4, 6

7.

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

8.

What will be the output of the program?

a)

12 15

b)

3 4 5 3 7 5

c)

15 15

d)

3 7 5 3 7 5

9.

What will be the output of the program?

a)

true

b)

false

c)

Compilation fails

d)

An exception is thrown at runtime

10.

What will be the output of the program?

a)

small

b)

huge

c)

tiny

d)

Compilation fails

11.

What will be the output of the program?

a)

5 3

b)

6 3

c)

6 4

d)

5 2

12.

What will be the output of the program?

a)

5 3

b)

8 3

c)

8 2

d)

8 5

13.

What will be the output of the program?

a)

0

b)

7

c)

8

d)

14

14.

What will be the output of the program?

a)

ok

b)

ok dokey

c)

dokey

d)

No output is produced

15.

What will be the output of the program?

a)

9 7 7 foo 7 7foo

b)

72 34 34 foo34 34foo

c)

9 7 7 foo34 34foo

d)

72 7 34 foo34 7foo

16.

What will be the output of the program?

a)

7 7

b)

14 0

c)

7 14

d)

14 14

17.

What will be the output of the program?

a)

null null 42

b)

0 0 42

c)

0 42 42

d)

0 0 0

18.

What will be the output of the program?

a)

count = 0

b)

count = 2

c)

count = 3

d)

count = 4

19.

What will be the output of the program?

a)

2

b)

4

c)

8

d)

16

20.

What is the output?

a)

There is a syntax error on line 1.

b)

There are syntax errors on lines 1 and 6.

c)

There are syntax errors on lines 1, 6, and 8.

d)

There is a syntax error on line 6.

21.

What will be the output of the program?

a)

j = -1

b)

j = 0

c)

j = 1

d)

Compilation fails.

22.

What will be the output of the program?

a)

i = 5 and j = 5

b)

i = 6 and j = 5

c)

i = 5 and j = 6

d)

i = 6 and j = 4

23.

What will be the output of the program?

a)

0 2 4

b)

0 2 4 5

c)

0 1 2 3 4

d)

Compilation fails.

24.

What will be the output of the program?

a)

a

b)

b

c)

c

d)

d

25.

Which cause a compiler error?

a)

int[ ] scores = {3, 5, 7};

b)

int [ ][ ] scores = {2,7,6}, {9,3,45};

c)

String cats[ ] = {"Fluffy", "Spot", "Zeus"};

d)

boolean results[ ] = new boolean [] {true, false, true};

e)

Integer results[ ] = {new Integer(3), new Integer(5), new Integer(8)};