This site requires JavaScript, please enable it in your browser!
Greenfoot back
joeenglish
joeenglish wrote ...

2015/12/31

Hello World Java Application

joeenglish joeenglish

2015/12/31

#
Hi, can anyone tell me how I can use Greenfoot to write/run the code below. Any help would be appreciated.
class HelloWorldApp {
    public static void main(String[] args) {
        System.out.println("Hello World!"); // Display the string.
    }
}
danpost danpost

2015/12/31

#
Greenfoot supplies a 'main' method to your project and you cannot have two in the same application. Change line 2 to this:
public HelloWorldApp() {
and create a subclass of World that creates a HelloWorldApp object:
public class MyWorld extends greenfoot.World {
    public MyWorld()
    {
        super(0, 0, 0);
        new HelloWorldApp();
    }
}
You need to login to post a reply.