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

6/6

Page

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

Which of these handles the exception when no catch is used?

Select an option to see the answer and solution.

Which of these methods is used to print stack trace?

Select an option to see the answer and solution.

Which of these keywords is used to generate an exception explicitly?

Select an option to see the answer and solution.

Which of these clause will be executed even if no exceptions are found?

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

Select an option to see the answer and solution.

What exception thrown by parseInt() method?

Select an option to see the answer and solution.

A single try block must be followed by which of these?

Select an option to see the answer and solution.

Which of these methods return description of an exception?

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

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

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");        	
        }
        finally 
        {
          System.out.print("C");
        }
    }
}

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 
        {
            System.out.print("Hello world ");
        }
        finally 
        {
            System.out.println("Finally executing ");
        }
    }
}

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

Select an option to see the answer and solution.

Which of these class is related to all the exceptions that are explicitly thrown?

Select an option to see the answer and solution.

Which of these keywords is not a part of exception handling?

Select an option to see the answer and solution.