• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help Me Out:

 
Prashanth Lingala
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Now My Question...


Please Explain???
Thank You For Your Time...
 
Martin Lerchster
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!

greetz
 
Fisher Daniel
Ranch Hand
Posts: 582
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
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...

thanks
daniel
 
Prashanth Lingala
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...



and



if somebody can shed more light, i would be grateful...
regards
Prashanth
 
Jeroen Wenting
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic