Multiple choice technology architecture

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? 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; }catch(IOException ioe) { } 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

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

When Hello.txt doesn't exist, FileInputStream throws FileNotFoundException. The catch block for FileNotFoundException executes, printing 'No such file found' and returning -1. Before returning, the finally block executes, printing 'Doing finally'. The return -1 completes after finally. Therefore output is: 'No such file found' then 'Doing finally' then the method returns -1. Note: The main method prints the return value, so we see -1 after 'Doing finally'.