In the first example, you can't have a statement that's not in a method. you could put the method in a constructor if you want it to print when the object is created, or you have to define a method like
and then call that method on the object.
in the second example, i think it's because there is no version of println that takes no argument - you have to pass it SOMETHING. and, if you change it to pass in a parameter, you'll be back at the first example.
in your third example, you have an enclosing method and a valid call to the println method. [ January 17, 2006: Message edited by: fred rosenberger ]
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Originally posted by fred rosenberger: in the second example, i think it's because there is no version of println that takes no argument - you have to pass it SOMETHING.
Nope, the second example has the same problem as the first. You are only allowed to put variable declarations outside of a method. Any code that is to be executed must be inside a method, as Fred says. There is a version of System.out.println() that takes no arguments.