Wednesday, 12 April 2017

q-15 What is output of the following program?
class ReturnValue
{
    public static void main(String[] args)
    {
        System.out.println(methodReturningValue());
    }

    static int methodReturningValue()
    {
        try
        {
            return 49;
        }
        catch (Exception e)
        {
            return 20;
        }
        finally
        {
              System.out.println("finally block");
         }
    }
}


a)Compilation fails b)runtime exception c)20 finally block    d)49 finally block



q-13 how to throw the exception explicitly?


class Test
{
public static void main(String[] args) {
explicitlyCall();
}
public static  void explicitlyCall()
{
try
{
               ArithmeticException ae=new ArithmeticException("ArithmethicException");
       throw ae;
 }
catch(ArithmeticException ae)
{
ae.printStackTrace();
}

}
}