Throw, Throws & Nested Try

1

What is the output of this program?

 
    class exception_handling {
        public static void main(String args[]) {
            try {
                int a = args.length;
                int b = 10 / a;
                System.out.print(a);
                try {
                    if (a == 1)
                        a = a / a - a;
                    if (a == 2) {
                        int c = {1};
                        c[8] = 9;
                    }
                }
                catch (ArrayIndexOutOfBoundException e) {
                    System.out.println("TypeA");
                }
                catch (ArithmeticException e) {
                    System.out.println("TypeB");
                }
            }
        }
    }

Note: Execution command line: $ java exception_handling one two

A. TypeA
B. TypeB
C. 0TypeA
D. 0TypeB

2

What is the output of this program?

  
    class exception_handling {
        public static void main(String args[]) {
            try {
                int a = args.length;
                int b = 10 / a;
                System.out.print(a);
                try {
                    if (a == 1)
                        a = a / a - a;
                    if (a == 2) {
                        int c = {1};
                        c[8] = 9;
                    }
                }
                catch (ArrayIndexOutOfBoundException e) {
                    System.out.println("TypeA");
                }
                catch (ArithmeticException e) {
                    System.out.println("TypeB");
                }
            }
        }
    }

Note : Execution commandline : $ java exception_handling one

A. TypeA
B. TypeB
C. 0TypeA
D. 0TypeB

3

What is the output of this program?

    class exception_handling {
        static void throwexception() throws ArithmeticException {        
            System.out.print("0");
            throw new ArithmeticException ("Exception");
        }
        public static void main(String args[]) {
            try {
                throwexception();
            }
            catch (ArithmeticException e) {
                System.out.println("A");
            }
        }
    }
A. A
B. 0
C. 0A
D. Exception

4

What is the output of this program?

 
    class exception_handling {
        public static void main(String args[]) {
            try {
                throw new NullPointerException ("Hello");
                System.out.print("A");
            }
            catch(ArithmeticException e) {
                System.out.print("B");        	
            }
        }
    }
A. A
B. B
C. Hello
D. Runtime Error

5

What is the output of this program?

    class exception_handling {
        public static void main(String args[]) {
            try {
                int a = args.length;
                int b = 10 / a;
                System.out.print(a);
                try {
                    if (a == 1)
                        a = a / a - a;
                    if (a == 2) {
                        int c = {1};
                        c[8] = 9;
                    }
                }
                catch (ArrayIndexOutOfBoundException e) {
                    System.out.println("TypeA");
                }
                catch (ArithmeticException e) {
                    System.out.println("TypeB");
                }
            }
        }
    }

Note : Execution command line : $ java exception_handling

A. TypeA
B. TypeB
C. 0TypeA
D. 0TypeB