wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Datatypes and Flowcontrol

Total questions: 15

Worksheet time: 8mins

Name
Class
Date
1.

Which of the following is NOT a primitive datatype?

a)

byte

b)

boolean

c)

String

d)

int

2.

What are the correct ways to declare a array? (Select appropriate answer)

a)

int a[][] = new int[5][5];

b)

int a[][] = new int[][4];

c)

int a[4][]=new int[][4];

d)

int a[4][4];

3.

Predict the output of the following code.

public class ColorTest

{

public static void main(String args[])

{

char choice='r';

switch(r)

{

case 'Y': case'y':

System.out.println("Yellow");

case 'R': case 'r' :

System.out.println("Red");

default:

System.out.println("Invalid color");

}

}

}

a)

Red

b)

Invalid Color

c)

Compilation fails

d)

Red

Invalid color

4.

Which of the following statements are CORRECT about Arrays in Java?

a)

Stores Homogeneous Data

b)

Size cannot be changed during run time

c)

Array index starts at 1

d)

Stores only user defined objects

5.

What is the output of the following code?

public class Test

{

public static void main(String args[])

{

int a[] = new int[2];

int index =1;

System.out.println(a[index++]);

}

}

a)

ArrayIndexOutofBoundsException

b)

null

c)

0

d)

Runtime Error

6.

Predict the output.

1 public class LiteralTest {

2 public static void main(String args[]) {

3 float f1=4.0;

4 float f2 = 2.0f;

5 float result= f1 * 2;

6 System.out.prinltn(result);

7 } }

a)

Compilation Error at line no.3

b)

Compilation Error at line no.4

c)

Prints 8.0

d)

Compilation Error at line no.6

7.

Public class TestOperator {

public static void main(String args[]) {

System.out.println(6^2);

} }

a)

2

b)

24

c)

Compiler Error

d)

No output

8.

What will be the output if we compile and execute the following code?

public TestBoolean{

public static void main(String args[]){

boolean b[] = new boolean[2];

boolean f = true;

System.out.println(b[0]+"::"+f);

if(b[1])

System.out.println(" in IF block");

else

System.out.println("in ELSE block");

} }

a)

false::true

in ELSE block

b)

true::true

in IF block

c)

false::true

in IF bloack

d)

true::true

in ELSE block

9.

To copy array elements from one array to another array, we can use (a)  

10.

The advantages of java array are _________________ and ____________________________

(a)  

11.

Java supports automatic garbage collection.

a)

True

b)

False

12.

Replace the following code with suitable equivalent.

if(a>b)

max= a;

else

max=b;

a)

(a>b)? max=a: max=b;

b)

max = (a>b)? a: b;

c)

max = a^((a^b) & (-(a<b)));

d)

max= b^((b^a) & (b<a))

13.

which access specifier strongly supports data hiding?

a)

default

b)

private

c)

public

d)

protected

14.

(a)   operator is used to compare an object with a specific type.

15.

Which of the following classes will be the parent class of all user-defined classes in java?

a)

Class

b)

Object

c)

String

d)

No parent class for user defined classes