wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Basics in Java

Total questions: 15

Worksheet time: 9mins

Name
Class
Date
1.

What type of literal is "null"?

a)

null Literal

b)

Character Literal

c)

String Literal

d)

It is not a Literal

2.

Function of the Scanner class to accept a float literal from the user is

a)

nextInt( )

b)

hasNext( )

c)

next( )

d)

nextFloat( )

3.

What is the value of c after int c = 'B'+3; is executed?

a)

101

b)

69

c)

Code is incorrect

d)

B3

4.

Select the types of programming constructs in Java.

a)

Selective

b)

Sequential

c)

Random

d)

Iterative

5.

r and l in r-value and l-value are

a)

read and location

b)

real and location

c)

reference and location

d)

right and left

6.

Absence of _________ in switch..case leads to fallthrough

a)

switch

b)

case

c)

default

d)

break

7.

The compiler of Java works on_______ to give _________.

a)

Byte Code, Source Code

b)

Source Code, Object Code

c)

Source Code, Byte Code

d)

Byte Code, Object Code

8.

Predict the value of k,

int k =10;

k=k+k++;

a)

11

b)

20

c)

21

d)

22

9.

Select the options that will yield a boolean value if a and b are of integer datatype and c is of boolean datatype.

a)

a=b

b)

a>b&&b>c

c)

a==b

d)

!c

10.

Predict the output of,

if(true)

{

System.out.println("true");

}

else

{

System.out.println("false");

}

a)

true

b)

false

c)

No Output

d)

Compile error

11.

What is the value of p after the following statement is executed?

int p=4538%100

a)

8

b)

38

c)

4538

d)

4

12.

Select all the statements that shows static initialisation of an integer variable x.

a)

x=10

b)

static int x;

c)

x=y+10;

d)

x=10.0

13.

Select all the statement that finds the above value

a)

Math.pow(x,1/3)

b)

Math.sqrt(x)

c)

Math.pow(x,3)

d)

Math.cbrt(x)

14.

Rewrite the following code block after removing the errors.

char m='H';

int p=m*5;

m=p;

4 lines
15.

Find the output of,

int x =4;

while(x>5)

{

System.out.println(x);

x++;

}

a)

6

7

8... infinity

b)

1

2

3

4

c)

No Output

d)

4

5