Java Programming - Exceptions - Discussion
Discussion Forum : Exceptions - Finding the output (Q.No. 1)
1.
What will be the output of the program?
public class Foo
{
public static void main(String[] args)
{
try
{
return;
}
finally
{
System.out.println( "Finally" );
}
}
}
Answer: Option
Explanation:
If you put a finally block after a try and its associated catch blocks, then once execution enters the try block, the code in that finally block will definitely be executed except in the following circumstances:
- An exception arising in the finally block itself.
- The death of the thread.
- The use of System.exit()
- Turning off the power to the CPU.
I suppose the last three could be classified as VM shutdown.
Discussion:
25 comments Page 1 of 3.
Suraj Dhaigude said:
5 years ago
In the try block, no any exception so no need to catch block control direct finally method so it's print finally.
(1)
P.vyshnavi said:
7 years ago
I think compilation fails because every try block having catch block is there but in this program, catch block is not there.
Correct me, if I am wrong.
Correct me, if I am wrong.
(1)
Pramod said:
1 decade ago
Thanks, What Difference System.exit(0), And System.exit(1)?
Suraj Dhaigude said:
5 years ago
Thanks all for giving the explanation.
ImdaduL Haque said:
7 years ago
I can't understand it. How can it work?
Bhanu said:
7 years ago
Hi Parul,
Exchanging the place or syntax of the main method will not be affected for execution of program except void must be before main.
Exchanging the place or syntax of the main method will not be affected for execution of program except void must be before main.
Rahul Nick said:
8 years ago
Thank you friends for giving this valuable knowledge.
Priyal said:
8 years ago
Nice explanation, I got more information from your conversation thanks a lot.
K.sindhu said:
8 years ago
Yeah, very nice explanation. Thanks a lot.
Tamilkumaran said:
8 years ago
Thanks for all your informations.
I got more information from your conversations.
I got more information from your conversations.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers