Home » JAVA Programming » Exceptions » Question
  1. What is the output of this program?
    class Myexception extends Exception 
    {
    int Execution;
    Myexception(int p)
    {
    Execution = p;
    }
    public String toString()
    {
    return "Execution";
    }
    }

    public class Result
    {
    static void compute (int p) throws Myexception
    {
    throw new Myexception(p);
    }
    public static void main(String args[])
    {
    try
    {
    compute(6);
    }
    catch(DevideByZeroException e)
    {
    System.out.print("Catch block Executed...");
    }
    }
    }
    1. 6
    2. Compilation Error
    3. Runtime Error
    4. Catch block Executed...
    5. None of these
Correct Option: C

Mexception is self defined exception, we are generating Myexception but catching DevideByZeroException which causes error.

error: cannot find symbol
catch(DevideByZeroException e)
^
symbol: class DevideByZeroException
location: class Result
1 error



Your comments will be displayed only after manual approval.