This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes return statement Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "return statement" Watch "return statement" New topic
Author

return statement

Bin Zhao
Ranch Hand

Joined: Oct 04, 2000
Posts: 73
Khalid's book said return; can exist in initializers(P149).But when I compile the following code,the compiler complains
public class MQ7
{
int i=0;
{
i=8;
return;
}
public MQ7()
{
i=10;
return;
}

public static void main(String args[])
{
MQ7 tf = new MQ7();
}
}
Did I miss something?
zulfiqar raza
Ranch Hand

Joined: Oct 18, 2000
Posts: 81
In the errata for Khalid, the workds 'and initializer' have been removed. So you are right, you can't use it in initializers.
Hemal Mehta
Ranch Hand

Joined: Nov 16, 2000
Posts: 101
Yes u did, u cannot do this kind of operation within the body of class itself, it has to b within a method, constructor or a
main body for ot to work...
 
Don't get me started about those stupid light bulbs.
 
subject: return statement
 
Similar Threads
Mapraputa Is
IllegalMonitorStateException (not what you think)
Habibi book: How many instances of remote object and Data object exist ?
Using "this" Operator and it's relation to readability
Shocking code