0

I am new in Java. Under fresh Lubuntu (12.10 x64 with all updates) I download Eclipse (3.8) from Lubuntu Software Center. My problem is that System.out.print() work only in class with main method.

5
  • No, don't post screenshots of you IDE etc. Describe your problem in text.
    – Mordechai
    Commented Mar 3, 2013 at 7:28
  • i have to ask and this is completely off topic ... but, how did you get the scroll bars to look like that?
    – vijay
    Commented Mar 3, 2013 at 7:42
  • I like Lubuntu because out of the box I can make black UI - in "Customize look and feel". Eclipse Juno have some problems with UI in dark DE (I installed Chrome plugin for better visual experience), but 3.8 from Software Center looks great in black UI of DE. Commented Mar 3, 2013 at 8:03
  • Reference to my previous comment When to not post screenshots
    – Mordechai
    Commented Mar 3, 2013 at 8:06
  • Sorry, I will be know. Commented Mar 3, 2013 at 8:30

2 Answers 2

1

Only variable declarations are allowed outside any method declarations. In your case:

System.out.println("test");

In Class2 was called outside a method declaration. (When do you expect it , to be called???)

2
  • Oh, really. I can type public int i only outside class with main method. Commented Mar 3, 2013 at 7:30
  • I didn't say only but to exclude method calls, not that you can't say public int i inside a method...
    – Mordechai
    Commented Mar 3, 2013 at 7:32
0

Lets try and say what MousEvent is trying to say ... but clearly.

When you write:

public class Foo {
    System.out.println("test");
}

you are putting a statement in a context where a statement is not allowed to appear.

In that context you are only allowed to place variable declarations, method declarations, type declarations and static or instance initializer blocks.

Statements (in general) are only permitted inside methods or static / instance initializer blocks.

0

Not the answer you're looking for? Browse other questions tagged or ask your own question.