What will be the output of the following Java code?

Minh Phượng

New member
What will be the output of the following Java code?
Code:
    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
A. TypeA
B. TypeB
C. Compilation Error
D. Runtime Error
 
Last edited by a moderator:
Answer: c
Explanation: try without catch or finally
Output:
Code:
$ javac exception_handling.java
$ java exception_handling
error: 'try' without 'catch', 'finally' or resource declarations
This section of our 1000+ Java MCQs focuses on creating threads in Java Programming Language.
 

Tìm kiếm

Back
Top