wood burning stoves*
The moose likes Beginning Java and the fly likes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark ""identifier expected" error please help" Watch ""identifier expected" error please help" New topic
Author

"identifier expected" error please help

Srinjoy Das
Greenhorn

Joined: Jul 11, 2004
Posts: 1
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

Joined: Feb 01, 2003
Posts: 127

Think about why the program prints null and 0.
[ July 11, 2004: Message edited by: Chris Allen ]
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

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.)


[Jess in Action][AskingGoodQuestions]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: "identifier expected" error please help
 
Similar Threads
Error in ArrayList and Enumeration program. need help please...
compile time errors
identifier expected
Problem with ObjectInputStream
namespaces