This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes output of this program? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "output of this program?" Watch "output of this program?" New topic
Author

output of this program?

Anto Telvin
Ranch Hand

Joined: Aug 12, 2008
Posts: 113
hi all
i have the following code i want to know what is happening after try is executed where the control will go after reaching return.

class exception
{
public static void main(String args[])
{
System.out.println("A");
try
{
return;
}
catch(Exception e)
{
System.out.println("B");
}
System.out.println("C");
}
}
thanks


Anto Telvin Mathew<br />Many of the life failures are people who did not realize how close they were to success when they give up. EDISON
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39478
    
  28
Have you tried it? What happened?
Anto Telvin
Ranch Hand

Joined: Aug 12, 2008
Posts: 113
i tried but it is printing only A that means control is moving out of the class is it like that or else and why it is not printing C
[ October 23, 2008: Message edited by: Anto Telvin ]
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3838

and why it is not printing C


What makes you think that it would print C? return statement is not like throwing an Exception. It transfers the control out of the method.


SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
Anto Telvin
Ranch Hand

Joined: Aug 12, 2008
Posts: 113
yup i got thanks
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19723
    
  20

Anto, you've been asked this before, but I'll repeat: please Use Code Tags. It really makes a difference.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Anoobkumar Padmanabhan
Ranch Hand

Joined: Aug 08, 2007
Posts: 103
Anto,

But if you put the print statement for C in a finally block, this will display. Am I right??


Thanks<br /> <br />Anoobkumar<br />SCJP 1.5
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18914
    
  40

But if you put the print statement for C in a finally block, this will display. Am I right??


Well, what happened when you tried it?

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: output of this program?