Java Exception Program Test-4

What will be the output of the following java code?

public class Test {

public static void main(String[] args) {

if (true) {

return;

}

try {

System.out.println(1);

} catch (ArithmeticException ex) {

System.out.println(2);

return;

}

}

}

What will be the output of the following java code?

public class Test {

public static void main(String[] args) {

System.out.print(1);

try {

System.out.print(2);

int i = 1 / 0;

} catch (ArithmeticException ex) {

System.out.println(3);

System.exit(0);

System.out.print(4);

} finally {

System.out.print(5);

}

System.out.print(6);

}

}

What will be the output of the following java code?

public class Test {

static int i=7;

public static void main(String[] args) {

Test r=null;

System.out.println(r.i);

}

}

What will be the output of the following java code?

public class Test {

public static void main(String[] args) {

Test t=new Test();

int a = t.hello();

System.out.println(a);

}

public int hello() {

try {

int i = 10 /0;

if (i > 0)

return 10;

} catch (Exception e) {

return 20;

} finally {

return 45;

}

}

}

What will be the output of the following java code?

public class Test {

public static void main(String[] args) {

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

i[5]=12;

System.out.println(i.length);

}

}