File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Help Me Out: Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Head First Android this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Help Me Out:" Watch "Help Me Out:" New topic

Help Me Out:

Prashanth Lingala
Ranch Hand

Joined: Nov 13, 2004
Posts: 66

Now My Question...

Please Explain???
Thank You For Your Time...

Have A Nice Day !!!
Martin Lerchster

Joined: Nov 29, 2004
Posts: 10
because you are not able to call a function within a class and out of a function declaration !

within a class you are able to declare functions, vars .... but not to call a function, you have to call a function within a function declaration!

Fisher Daniel
Ranch Hand

Joined: Sep 14, 2001
Posts: 582
Your statement (System.out.println) must be inside a method.
You just can declare and initialize class variable and instance variable at that place.
You can learn about that in the Java Language Specification

Correct me if i am wrong...

Prashanth Lingala
Ranch Hand

Joined: Nov 13, 2004
Posts: 66
I dont know where to look specifically in JLS
but i am assuming that you cant write System.out.println ina class ...
you need to have that in a method...


if somebody can shed more light, i would be grateful...
Jeroen Wenting
Ranch Hand

Joined: Oct 12, 2000
Posts: 5093
You can indeed not have any code outside a method or initializer block.
The one exception to this are calls to new to initialize objects, and those calls can only contain literals as arguments if I'm not mistaken.

wood burning stoves
subject: Help Me Out:
It's not a secret anymore!