Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

return statement

 
Bin Zhao
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 101
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic