Saturday, 25 May 2013

Exception - 17 -

What will be output if you try to compile and run the following code, but there is no file called Hello.txt in the current directory?

package net.dharmaraj;

import java.io.*;

public class Mine
{
    public static void main(String argv[])
    {
        Mine m = new Mine();
        System.out.println(m.amethod());
    }

    public int amethod()
    {
        try
        {
            FileInputStream dis = new FileInputStream("Hello.txt");
        }
        catch (FileNotFoundException fne)
        {
            System.out.println("No such file found");
            return -1;
        }

        finally
        {
            System.out.println("Doing finally");
        }
        return 0;
    }
}


1) No such file found 
2 No such file found ,-1 
3) No such file found, Doing finally, -1 
4) 0 



Compile Out Put:--
No such file found
Doing finally
-1

No comments:

Post a Comment