82.
What will be the output of the following Java code?
class exception_handling 
{
    public static void main(String args[]) 
    {
        try 
        {
            int a = args.length;
            int b = 10 / a;
            System.out.print(a);
        }
        catch (ArithmeticException e) 
        {
                System.out.println("1");
        }
    }
}

Note : Execution command line : $ java exception_handling

84.
What is the use of try & catch?

85.
What will be the output of the following Java code?
class Output 
{
    public static void main(String args[]) 
    {
       try 
       {
           int a = 0;
           int b = 5;
           int c = a / b;
           System.out.print("Hello");
       }
       catch(Exception e) 
       {
           System.out.print("World");
       } 
    }
}

86.
What will be the output of the following Java code?
class Output 
{
    public static void main(String args[]) 
    {
       try
       {
           int a = 0;
           int b = 5;
           int c = b / a;
           System.out.print("Hello");
       }
       catch(Exception e) 
       {
           System.out.print("World");
       } 
       finally 
       {
           System.out.print("World");
       } 
    }
}

87.
What will be the output of the following Java code?
class exception_handling 
{
    public static void main(String args[]) 
    {
        try 
        {
            System.out.print("A");
            throw new NullPointerException ("Hello");
        }
        catch(ArithmeticException e) 
        {
            System.out.print("B");        	
        }
    }
}

89.
What will be the output of the following Java 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

90.
What will be the output of the following Java code?
class Myexception extends Exception 
{
int detail;
    Myexception(int a)
    {
    detail = a;
}
public String toString()
    {
  return "detail";
}
}
class Output
{
    static void compute (int a) throws Myexception
    {
   throw new Myexception(a);	 
}
public static void main(String args[])
    {
        try 
        {
            compute(3);
        }
       catch(Exception e)
       {
           System.out.print("Exception");
       } 
    }
}

Read More Section(Exceptions)

Each Section contains maximum 100 MCQs question on Exceptions. To get more questions visit other sections.