Class Return{ int display(){ try{ return 1; } finally{ return 2; } } public static void main(String args[]){ Return r=new Return(); System.out.println(r.display()); }}when i executed on jdk 1.4 i got the compile time error as finally clause does not normally completed?but in khalid moghal book its executed and result is printed.

Questions by sadashivarao   answers by sadashivarao

Showing Answers 1 - 2 of 2 Answers

ram

  • Aug 21st, 2006
 

You should get the return value as 2.

You won't get a compilation error. unless you made some typo.

the finally will execute in this senario and return you a value of 2.

  Was this answer useful?  Yes

sairam

  • Oct 27th, 2006
 

There will be no compilation error. The answer will be 2. You will get only the warning "finally clause does not normally completed" not the error.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions