Thursday, September 15, 2005

All about arrays

class Test {

public static void main(String [] args) {

int[] i = new int[-1];

}

}

o/p ==> runtime error ==> java.lang.NegativeArrayException

class Test {

public static void main(String [] args) {

int[] i = new int[];

System.out.println("Octal 011 = " + i);

}

}

o/p ==> compile time error

class Test {

public static void main(String [] args) {

int[] i = new int[0];

System.out.println("Octal 011 = " + i[0]);

}

}

o/p ==> runtime error ==> java.lang.ArrayIndexOutOfBoundsException

class Test {

public static void main(String [] args) {

int a1[], a2[]; //1

int[] a3, []a4; //2

int[] a5, a6[]; //3

int[] a7, a8[]; //4

}

}

o/p ==> compile time error at 2

An array variable is declared by placing brackets after the indentifier (or) after the type name. A compiler time error occurs at line marked (2) because th brackets appearing before the identifier for array variable a4 are not associated with the type (or) the identifier


0 Comments:

Post a Comment

<< Home