aspose file tools*
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" Watch ""identifier expected" error" New topic
Author

"identifier expected" error

Joe Jones
Greenhorn

Joined: Sep 03, 2002
Posts: 1
Hi all, I'm new to java and would like some help figuring out what I'm doing wrong. Here's my code:
-----------
package testpackage;

public class Class1 {

public String firstMethod() {
return "My java class!";
}
}
-----------
package testpackage;

public class Class2 {

Class1 c = new Class1();

System.out.println(c.firstMethod());
}
-----------

Problem is, when Class2 is compiled I'm seeing the following error:
... Class2.java:7: <identifier> expected

Can someone tell me how I can correct this?

Thanks!
Greg K.
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
You can list a method call like that outside of a method or initializer block. Try putting braces around the line.
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

Or maybe you wanted to put it in the main() method ?


[ March 02, 2006: Message edited by: Satou kurinosuke ]

[My Blog]
All roads lead to JavaRanch
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

"Greg K.,"

Welcome to JavaRanch!

Please revise your display name to meet the JavaRanch Naming Policy. To maintain the friendly atmosphere here at the ranch, we like folks to use real (or at least real-looking) names, with a first and a last name.

You can edit your name here.

Thank you for your prompt attention, and enjoy the ranch!

-Marc


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: "identifier expected" error