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

4/6

Page

Pick an option on a question to see the right 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");
       } 
    }
}

Select an option to see the answer and solution.

Which of these class is related to all the exceptions that cannot be caught?

Select an option to see the answer and solution.

Which of these classes is used to define exceptions?

Select an option to see the answer and solution.

Which of these class is related to all the exceptions that can be caught by using catch?

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("Hello" + " " + 1 / 0);
        }
        finally 
        {
      System.out.print("World");        	
        }
    }
}

Select an option to see the answer and solution.

Which of these classes is super class of Exception class?

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 two

Select an option to see the answer and solution.

Which of these statements is incorrect?

Select an option to see the answer and solution.

Which of these keywords are used for the block to handle the exceptions generated by try block?

Select an option to see the answer and solution.

Which of these keywords must be used to monitor for exceptions?

Select an option to see the answer and solution.

What will be the output of the following Java code?
public class A
 {  
    public static void main(String[] args) 
    {
        try 
        { 
            return; 
        } 
        finally 
        {
            System.out.println( "Finally" ); 
        } 
    } 
}

Select an option to see the answer and solution.

Which of the following classes can catch all exceptions which cannot be caught?

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

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 i, sum;
            sum = 10;
            for (i = -1; i < 3 ;++i) 
            {
                sum = (sum / i);
            System.out.print(i);
            }
        }
        catch(ArithmeticException e) 
        {     	
            System.out.print("0");
        }
    }
}

Select an option to see the answer and solution.

Which of these keywords are used for the block to be examined for exceptions?

Select an option to see the answer and solution.

Which part of code gets executed whether exception is caught or not?

Select an option to see the answer and solution.

Which of these keywords must be used to handle the exception thrown by try block in some rational manner?

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 = 1;
                    int b = 10 / a;
                    try 
                    {
                         if (a == 1)
                             a = a / a - a;
                         if (a == 2) 
                         {
                             int c[] = {1};
                             c[8] = 9;
                         }
                    }
                    finally 
                    {
                        System.out.print("A");
                    }
                }
                catch (Exception e) 
                {
                        System.out.println("B");
                }
            }
        }

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");
       }
       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 
        {
            throw new NullPointerException ("Hello");
            System.out.print("A");
        }
        catch(ArithmeticException e) 
        {
      System.out.print("B");        	
        }
    }
}

Select an option to see the answer and solution.