Submitted by heartin on Tue, 09/08/2015 - 13:17
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
Submitted by heartin on Tue, 09/08/2015 - 13:11
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.
Submitted by heartin on Tue, 09/08/2015 - 09:03
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
Submitted by heartin on Tue, 09/08/2015 - 08:56
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
Submitted by heartin on Tue, 09/08/2015 - 08:47
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.
Pages