It's not a secret anymore!
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
JavaRanch » Java Forums » Java » Beginning Java
Bookmark ""identifier expected" error please help" Watch ""identifier expected" error please help" New topic

"identifier expected" error please help

Srinjoy Das

Joined: Jul 11, 2004
Posts: 1
THe following code yields an identifier expected error at * can somebody help

class student
int marks;
String name;

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

Joined: Jul 08, 2003
Posts: 24199

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:
subject: "identifier expected" error please help
It's not a secret anymore!