Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Code Junction 4

Total questions: 20

Worksheet time: 43mins

Name
Class
Date
1.

Number of primitive data types in Java are?

a)

6

b)

7

c)

8

d)

9

2.

What is the size of float and double in java?

a)

32 and 64

b)

32 and 32

c)

64 and 64

d)

64 and 32

3.

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)

I

d)

24 I

4.

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

5.

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

6.

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

7.

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

8.

Identify what can directly access and change the value of the variable res.

Package com.mypackage;

Public class Solution{

Private int res = 100; }

a)

any class

b)

only solution class

c)

any class that extends solution

d)

none

9.

Identify the output of the following program.

String str = “abcde”;

System.out.println(str.substring(1, 3));

a)

abc

b)

bc

c)

bcd

d)

cd

10.

Identify the output of the following program.

Public class Test{

Public static void main(String argos[]){

String str1 = “one”;

String str2 = “two”;

System.out.println(str1.concat(str2)); } }

a)

one

b)

two

c)

onetwo

d)

twoone

11.

How many objects will be created in the following?

String a = new String(“Interviewbit”);

String b = new String(“Interviewbit”);

Strinc c = “Interviewbit”;

String d = “Interviewbit”;

a)

2

b)

3

c)

4

d)

none

12.

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

13.

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

14.

Identify the return type of a method that does not return any value.

a)

int

b)

void

c)

double

d)

none

15.

Identify the modifier which cannot be used for constructor.

a)

public

b)

protected

c)

private

d)

static

16.

What is the variables declared in a class for the use of all methods of the class called?

a)

object

b)

instance variable

c)

reference variable

d)

none

17.

Find the output of the following code.

Public class Solution{

Public static void main(String args[]){

Int i;

for(i = 1; i < 6; i++){

if(i > 3) continue; }

System.out.println(i); } }

a)

3

b)

4

c)

5

d)

6

18.

How many times will “Interviewbit” be printed.

Int count = 0;

do{ System.out.println(“Interviewbit”);

count++; }

while(count < 10);

a)

8

b)

9

c)

10

d)

11

19.

Identify the infinite loop.

a)

for(; ;)

b)

for(int i=0; i < 1; i--)

c)

for(int i = 0; ;i++)

d)

All of the above

20.

Exception created by try block is caught in which block?

a)

catch

b)

throw

c)

final

d)

none