arrays

Quiz Guidelines

 

Multiple Choice Question

QID: 
410

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 = 30 ;
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 30
D. It will prints 30 20 30
E. It will prints 0 20 30

Multiple Choice Question

QID: 
409

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

Multiple Choice Question

QID: 
408

What will happen when the following code is compiled and run?

class AX{
static int[] x = new int[0];
static{
x[0] = 10;
}
public static void main(String[] args){
AX ax = new AX();
}
}

Select 1 option

A. It will throw NullPointerException at runtime.
B. It will throw ArrayIndexOutOfBoundsException at runtime.
C. It will throw ExceptionInInitializerError at runtime.
D. It will not compile.

Multiple Choice Question

QID: 
407

Which of the following statements about an array are correct?

Select 1 option

A. An array can dynamically grow in size.
B. Arrays can be created only for primitive types.
C. Every array has a built in property named 'size' which tells you the number of elements in the array.
D. Every array has in implicit method named 'length' which tells you the number of elements in the array.
E. Element indexing starts at 0.

Multiple Choice Question

QID: 
406

What will the following program print?

public class TestClass{
public static void main(String[] args){
String str = "111";
boolean[] bA = new boolean[1];
if( bA[0] ) str = "222";
System.out.println(str);
}
}

Select 1 option

A. 111
B. 222
C. It will not compile as bA[0] is uninitialized.
D. It will throw an exception at runtime.
E. None of the above.

Pages