Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

3
  • And to call it from another class you instantiate an object of HelloWorld? sometimes when I try to add a method under main, the IDE just don't recognize it at all , Eclipse, it keep telling : Syntax error, insert ";" to complete LocalVariableDeclarationStatement Commented Feb 25, 2016 at 1:22
  • (1) You cannot insert a method declaration into another method. Here, main is also method, so you cannot insert a method declaration into the main method. (2) HelloWorld has only static elements. This means there is no point to create an instance of it. To call the main method from another class, you would do it just as in your question: HelloWorld.main(new String[0]);. It does not return a value, but only print it to the console. Are you sure you want to do this? Commented Feb 25, 2016 at 1:52
  • You are welcome. However, you might want to ask a new question for that, since it seems to be quite different from this question. Commented Feb 25, 2016 at 2:26