File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes really stupid question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "really stupid question" Watch "really stupid question" New topic
Author

really stupid question

Peg Garland
Greenhorn

Joined: Aug 20, 2008
Posts: 1
I am working through the study guide for SCJP. On the first example I created a class:

public class Fruit {
System.out.println("Inside Fruit class");

}

It won't compile!
cannot find symbol: class out
location: java.lang.System.out

I imported java.lang.*; and that doesn't help. In the class with the main method, I can use System.out.println("Inside Main") with no imports. What is the difference?
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Welcome to JavaRanch!

Basically, Java classes contain fields and methods. Statements like...

System.out.println("Inside Fruit class.");

...must be inside a method body. (Or a constructor body, or an initialization block... But not by itself inside the class definition.)


"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
Mark Vedder
Ranch Hand

Joined: Dec 17, 2003
Posts: 624

You are calling a method outside a method, constructor or initializer block. You need to move your System.out.println() into one of those.
arulk pillai
Author
Ranch Hand

Joined: May 31, 2007
Posts: 3219
In Java java.lang.*; is implictly imported. Are you using any Java IDE or using text pad?


Java Interview Questions and Answers Blog | Amazon.com profile | Java Interview Books
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38481
    
  23
That isn't a stupid question at all. But please, in future, tell us what your posts are about; see this FAQ.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38481
    
  23
Originally posted by arulk pillai:
In Java java.lang.*; is implictly imported. Are you using any Java IDE or using text pad?
I think the compiler has imputed "java.lang.System" to "System" and is simply using its fully qualified name.
eshu khare
Ranch Hand

Joined: Aug 01, 2008
Posts: 44
Hi,

the above code in asked doubt will compile witout 'MAIN'?


Thanks & Regards
Eshu Khare
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38481
    
  23
Have you tried it? Have you read the whole of this Thread? Have you ever had a class without a main (not MAIN) method?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: really stupid question