Problem based on programming


Q1. What RuntimeException, if any, will the following program throw?

class Exception1
{
    public static void main(String[] args)
    {
        int x = 1/0;
    }
}

Q2. How can you tell whether an exception is checked or unchecked? What is required of checked exceptions that is not required of those that are unchecked?

Q3. What is the output of the following program?

class Exception2
{
    public static void main(String[] args)
    {
        try
        {
            aMethod();
            System.out.println("After the call");
        }
        catch (ArithmeticException exception)
        {
            System.out.println("Arithmetic Exception");
        }
        catch (RuntimeException exception)
        {
            System.out.println("Runtime Exception");
        }
        System.out.println("After the try-catch statement");
    }
    private static void aMethod() throws RuntimeException
    {
        int x = 1/0;
    }
}

What will happen if the order of the catch blocks is reversed?

Q4. Why won't the following program compile?

class Exception3
{
    public static void main(String[] args)
    {
        if (Integer.parseInt(args[0]) == 0)
            throw new Exception("Invalid Command Line Argument");
    }
}

Correct it so it will compile.

Q5. Explain the difference between the keywords throw and throws. When is each used?

Request for Solution File

Ask an Expert for Answer!!
Programming Languages: Problem based on programming
Reference No:- TGS0535268

Expected delivery within 24 Hours