| 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: 24051
|
|
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]
|
 |
 |
|
|
subject: "identifier expected" error please help
|
|
|