This week's book giveaway is in the Agile forum.
We're giving away four copies of Head First Agile and have Andrew Stellman & Jennifer Greene on-line!
See this thread for details.
Win a copy of Head First Agile this week in the Agile forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

illegal start of type  RSS feed

 
Shafian Kisna
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Everyone,

Can some one pls help me? I am not sure why was I thrown this error:-
Revision.java:37: illegal start of type
for (int j=0;j<tes.length; j++)
^
Revision.java:41: <identifier> expected
^
2 errors

Source code is as follows:-

public class Revision
{
.
..
.
.
//3
int tes[] = new int[4];
for (int j=0;j<tes.length; j++)
{
tes[j] = j;
}
.
.
..
}

Pls advice

Thanks & Appreciate the time!
 
Keith Lynn
Ranch Hand
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You cannot place code like a for loop in a class definition outside of a method or block.
[ March 07, 2006: Message edited by: Keith Lynn ]
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In general, classes have "state" (variables) and "behavior" (methods). When you want your code to "do" something (like iterate through a loop), that behavior should be defined inside a method.

[ March 07, 2006: Message edited by: marc weber ]
 
Shafian Kisna
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
Thanks a lot...for the source

It worked...

Regards
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!