Vidyalelo
Java Programming · all questions

Exceptions
practice.

Practice every MCQ with options. Use Show answers when you want the correct option and solution.

115

Questions

5/6

Page

Pick an option on a question to see the right answer and solution.

Which of these methods return localized description of an exception?

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

When does Exceptions in Java arises in code sequence?

Select an option to see the answer and solution.

What is the use of try & catch?

Select an option to see the answer and solution.

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");
       } 
    }
}

Select an option to see the answer and solution.

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");
       } 
    }
}

Select an option to see the answer and solution.

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");        	
        }
    }
}

Select an option to see the answer and solution.

Which of these is a super class of all exceptional type classes?

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

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");
       } 
    }
}

Select an option to see the answer and solution.

Which of these keywords are used for generating an exception manually?

Select an option to see the answer and solution.

What will be the output of the following Java program?
class exception_handling 
{
    public static void main(String args[]) 
    {
        try 
       {
            int a, b;
            b = 0;
            a = 5 / b;
            System.out.print("A");
        }
        catch(ArithmeticException e) 
        {
      System.out.print("B");        	
        }
    }
}

Select an option to see the answer and solution.

Which of the following is a super class of all exception type classes?

Select an option to see the answer and solution.

At runtime, error is recoverable.

Select an option to see the answer and solution.

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(Myexception e)
       {
           System.out.print("Exception");
       } 
    }
}

Select an option to see the answer and solution.

Which of these keywords is used to by the calling function to guard against the exception that is thrown by called function?

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

Which of the following keyword is used by a calling function to handle exception thrown by a called function?

Select an option to see the answer and solution.

Which of the following operators is used to generate instance of an exception which can be thrown using throw?

Select an option to see the answer and solution.

Which of the following handles the exception when a catch is not used?

Select an option to see the answer and solution.