Search code examples
javadrjava

Error in "Hello World" when compiling on Dr. Java?


I am learning Java, and am testing a simple 'Hello World' program given to me by my teacher. I am using Dr. Java on 64-bit Ubuntu 12.04 LTS.

Code is below:

public class Hello_World
{
    public void go()
    {
        System.out.println("Hello, World!");
    }
}

I hit the F5 key, and the code compiles. After that, I enter the lines below:

greet = new Hello_World();
greet.go();

The output is supposed to be Hello, World!, but I am getting Static Error: Undefined name 'greet' instead. What am I doing wrong?

Please forgive me if I this is an easy fix (it probably is). I searched SE, but did not find anything that helped.


Solution

  • You need the code:

    Hello_World greet = new Hello_World();
    greet.go();
    

    in a main method, which is the point of execution of a java program. http://csis.pace.edu/~bergin/KarelJava2ed/ch2/javamain.html