wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

To meet the horizon

Total questions: 20

Worksheet time: 20mins

Name
Class
Date
1.

Which of the following option leads to the portability and security of Java?

a)

Bytecode is executed by JVM

b)

The applet makes the Java code secure and portable

c)

Use of exception handling

d)

Dynamic binding between objects

2.

Which of the following is a valid long literal?

a)

8097

b)

L990023

c)

904423

d)

0xF029L

3.

What does the expression float a = 0 / 0 return?

a)

0

b)

Not a Number

c)

Infinity

d)

Run time exception

4.

What would be the result of attempting to compile and run the following code?


public class HelloWorld{

public static void main(String[] args){

double[] x = new double[]{1, 2, 3};

System.out.println("Value is " + x[1]);

}

}

a)

The program has a compile error because the syntax new double[]{1, 2, 3} is wrong and it should be replaced by {1, 2, 3}.

b)

The program has a compile error because the syntax new double[]{1, 2, 3} is wrong and it should be replaced by new double[3]{1, 2, 3};

c)

The program has a compile error because the syntax new double[]{1, 2, 3} is wrong and it should be replaced by new double[]{1.0, 2.0, 3.0};

d)

The program compiles and runs fine and the output.

5.

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

a)

int [] myList = {};

b)

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

c)

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

d)

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

6.

Which is the correct way of knowing Array Size (int ary[]) in Java?

a)

ary.length()

b)

ary.length

c)

ary->length()

d)

ary->length

7.

What is the output of the below Java program?


int balls[], rounds=3;

balls = new int[rounds];

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

balls[i] = (i+1)*2;

for(int j=0; j<balls.length; j++)

System.out.print(balls[j] + ",");

a)

0,2,4,

b)

1,2,3,

c)

2,4,6,

d)

Compiler error

8.

class Test {

public static void swap(Integer i, Integer j) {

Integer temp = new Integer(i);

i = j;

j = temp;

}

public static void main(String[] args) {

Integer i = new Integer(10);

Integer j = new Integer(20);

swap(i, j);

System.out.println("i = " + i + ", j = " + j);

}

}

a)

i = 10, j = 20

b)

i = 20, j = 10

c)

i = 10, j = 10

d)

i = 20, j = 20

9.

class Main {

public static void main(String args[]){

final int i;

i = 20;

i = 30;

System.out.println(i);

}

}

a)

20

b)

30

c)

0

d)

Error

10.

Given the code :

void Star (Point P1, Point P2)

{

Point PM = new Point( ) ;

int P1 = T1.h + t1.m * 60 ;

int P2 = T2.h + t2.m*60 ;

int tm3 = (t1>t2) ? (t1-t2) : ( t2 – t1) ;

h = tm3/ 60 ;

m = tm3 % 60 ;

}


What is 'odd one out' in the code?

a)

h and m not declared

b)

P1 and P2 of no use

c)

object PM unused

d)

more than one statements odd

11.

The expansion of P XOR Q is :

a)

P’.Q + P’.Q’

b)

P.Q + P’Q’

c)

P’.Q + P.Q’

d)

P.Q + P.Q’

12.

The complement of P’.Q’ + P.Q’ will be

a)

( (P+Q) . (P’ + Q) )’

b)

( (P+Q) . (P + Q’) )’

c)

( P+Q ) . (P’ + Q)

d)

( P’+Q’ ) . (P + Q’)

13.

If A=1, B=0, C=0 and D=0, then the maxterm will be:

a)

A . B’ . C’ . D’

b)

A’ + B + C + D

c)

A + B’ + C’ + D’

d)

A’ . B . C . D

14.

If A = 0, B = 1, C = 1 and D = 0, then the minterm will be:

a)

A’ . B . C . D’

b)

A + B’ + C’ + D

c)

A . B’ . C’ . D

d)

A’ + B + C + D’

15.

The expression A.B’ + A + B’.C will be:

a)

A tautology

b)

A contradiction

c)

A contingency

d)

Invalid expression

16.

Given the code :

void gnSpeed ( )

{

int x = 5, y = 10, p = 18 ;

if ( p > y )

{

x = x + 10 ;

}

else if ( x > 10)

{

x = p + y ;

}

}

What will be the final value of x?

a)

18

b)

23

c)

28

d)

None of the above

17.

Given the code :

void gnSpread ( )

{

int d = 1 , m = 10 , n = 9, p = 0 ;

if ( m > n )

{

p = 1;

}

if ( d = = 1 )

{

p = 2;

}

else

{

p = 3;

}

}

What will be the final value of p ?

a)

1

b)

2

c)

3

d)

None of the above

18.

Given code, what will be the output:

int k = 4 , g = 6 ;

while ( k++ < g)

System.out.println ( “Yoko = “ + k *g ) ;

System.out.println (“Hama = “ + k *g ) ;

a)

Yoko = 30

Hama = 36

Hama = 42

b)

Yoko = 30

Yoko = 36

Hama = 42

c)

Yoko = 25

Yoko = 30

Hama = 36

d)

None of the above

19.

Given the code :

void gnSpeed ( )

{

int x = 52 , y = 7651 , p = 18 ;

if ( p > y || y > x )

{

y = y % 100 ;

}

p = ( x > y ) ? (p+2) : (p-8) ;

}

What will be the final value of p ?

a)

18

b)

10

c)

20

d)

28

20.

Given the code:

int d = 69 , p = 96 ;

do

{

System.out.print ( d + p ) ;

} while (d != p ) ;

a)

The code is infinite

b)

The code will never run

c)

The code will run once

d)

Error in the code