Can anyone help me out by telling what will be the output of the above code and how is it step by step so that I can understand it exactly !!
dont be disappointed what other people have told. This fourn is for beginner and any sort of questions can be asked.
coming down to your question:
The output will be :
A & B will be displayed because of normal flow execution then the exception is thrown which is caught by a catch block hence the program flow comes to catch block and 'D' is displayed and not 'C'. The finally block has to be executed in all cases whether the exception is caught or not. So 'E' is displayed and at last the control comes out from try-catch-finally block and 'F' is displayed.
...This fourn is for beginner and any sort of questions can be asked.
Harshit, this is true, however, simply asking for the answers to questions, without trying it oneself, is not a productive method of learning don't you think, after all we shouldn't be doing others homework for them.
Generally, we expect people to ShowSomeEffort. Posting some code and asking 'what is the output' pretty much shows you have put in NO effort. The LEAST you could do is run the code yourself. That way, you would see exactly what the output is. Then, if you don't understand it, you can ask a more focused question, like "I was expecting output A, but got output B and don't understand why".
further, you could tell us which specific part you don't understand. Do you know what System.out.print() does? Do you know what a try/catch block is? what the finally is?
In other words, the more specific your question, the easier it is for someone to help you, and the better response you'll get. You may want to read a lot of this. They really are great suggestions on how to get the most out of this site.
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Hmmm.... I can see that button on all posts, but that's because I'm a moderator. I assumed that as a normal user you would be able to delete your own posts (we had such a feature in the old forum software - since the beginning of this year we have new forum software). I'll ask the other moderators about it.
Jesper Young wrote:I assumed that as a normal user you would be able to delete your own posts (we had such a feature in the old forum software - since the beginning of this year we have new forum software). I'll ask the other moderators about it. I deleted the empty post for you.
We are no longer able to delete our own post, with the new forum software according to this (Don't know about any update after that)
firstly I am sorry that a huge matter has been created about nothing......You could have answered and then say Be EXPERIMENTING guy from next time..........
And regarding the question ,this code will not compile.....because of unreachable statement.....