Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

"identifier expected" error please help

 
Srinjoy Das
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
THe following code yields an identifier expected error at * can somebody help

class student
{
int marks;
String name;
student()
{
marks=0;
}

System.out.println(name);*
System.out.println(marks);
}
 
Chris Allen
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Think about why the program prints null and 0.
[ July 11, 2004: Message edited by: Chris Allen ]
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Srinjoy,

Welcome to JavaRanch!

Chris' question aside, the error message is telling you (in a hard-to-understand way) that you've got Java statements appearing outside of a method body. At the "top level" of a class, you can only have member variable declarations, not statements like the "System.out.println()" calls. Those have to be in a method (as in Chris's example.)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic