Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Java Quiz (Basics)

Total questions: 10

Worksheet time: 5mins

Name
Class
Date
1.

Find the output of the following code.

int Integer = 24;

char String = ‘I’;

System.out.print(Integer);

System.out.print(String);

a)

Compile error

b)

Throws Exception

c)

1

d)

241

2.

Find the output of the following program.

public class Solution

{

public static void main(String[] args)

{ short x = 10; x = x * 5; System.out.print(x); } }

a)

50

b)

10

c)

compile error

d)

Exception

3.

Find the output of the following program.

public class Solution

{

public static void main(String[] args)

{ byte x = 127; x++; x++; System.out.print(x); } }

a)

-127

b)

127

c)

129

d)

2

4.

Find the output of the following program.

public class Solution

{ public static void main(String[] args)

{ int[] x = {120, 200, 016};

for(int i = 0; i < x.length; i++)

{ System.out.print(x[i] + “ “);

} } }

a)

120 200 016

b)

120 200 14

c)

120 200 16

d)

None

5.

When an array is passed to a method, what does the method receive?

a)

The reference of the array

b)

The copy of the array

c)

Length of the array

d)

Copy of first element

6.

Find the value of A[1] after execution of the following program.

int[] A = {0,2,4,1,3}; for(int i = 0; i < A.length; i++){ A[i] = A[(A[i] + 3) % A.length]; }


a)

0

b)

1

c)

2

d)

3

7.

Arrays in java are-

a)

Object refrences

b)

Objects

c)

Primitive data type

d)

None

8.

Find the output of the following code.

int ++a = 100;

System.out.println(++a);

a)

101

b)

Compile error as ++a is not a valid identifier

c)

100

d)

None

9.

Find the output of the following code.

if(1 + 1 + 1 + 1 + 1 == 5)

{

System.out.print(“TRUE”);

}

else

{ System.out.print(“FALSE”); }

a)

TRUE

b)

FALSE

c)

Compile error

d)

None

10.

Find the output of the following code.

Public class Solution

{

Public static void main(String… argos)

{ Int x = 5; x * = (3 + 7); System.out.println(x);

}}

a)

50

b)

22

c)

10

d)

None