JavaQuizzes

Quiz Guidelines

 

Multiple Choice Question

QID: 
22

Consider the following class...

class Test{

public static void main(String[ ] args){

int[] a = { 1, 2, 3, 4 };

int[] b = { 2, 3, 1, 0 };

System.out.println( a [ (a = b)[3] ] );

}

}

What will it print when compiled and run ?

Select 1 option

A. It will not compile.

B. It will throw ArrayIndexOutOfBoundsException when run.

C. It will print 1.

D. It will print 3.

E. It will print 4

F. It will print 2

Multiple Choice Question

QID: 
23

What will be the result of trying to compile and execute of the following program?

public class TestClass{

public static void main(String args[] ){

int i = 0 ;

int[] iA = {10, 20} ;

iA[i] = i = 40 ;

System.out.println(""+ iA[ 0 ] + " " + iA[ 1 ] + " "+i) ;

}

}

Select 1 option

A. It will throw ArrayIndexOutofBoundsException at Runtime.

B. Compile time Error.

C. It will prints 10 20 40

D. It will prints 40 20 40

E. It will prints 0 20 40

Multiple Choice Question

QID: 
24

Is it possible to create arrays of length zero?

 

Select 1 option

A. Yes, you can create arrays of any type with length zero.

B. Yes, but only for primitive datatypes.

C. Yes, but only for arrays of object references.

D. Yes, and it is same as a null Array.

E. No, arrays of length zero do not exist in Java.

True or False

QID: 
25
class Test{

public static int[ ] getArray() { return null; }

public static void main(String[] args){

int index = 1;

try{

getArray()[index=2]++;

}

catch (Exception e){ } //empty catch

System.out.println("index = " + index);

}

}

 

Select 1 option

A. True

B. False

Multiple Choice Question

QID: 
26
import java.util.* ;

public class ListTest{

public static void main(String args[]){

List s1 = new ArrayList( );

s1.add("a");

s1.add("b");

s1.add(1, "c");

List s2 = new ArrayList( s1.subList(1, 1) );

s1.addAll(s2);

System.out.println(s1);

}  }

What sequence of digits will the following program print?

 

Select 1 option

A. The sequence a, b, c is printed.

B. The sequence a, b, c, b is printed.

C. The sequence a, c, b, c is printed.

D. The sequence a, c, b is printed.

E. None of the above.

Pages