HQuser
HQuser

Reputation: 640

How Eclipse (IDE) can run main method in Java without a public class?

I have created a new project in Eclipse IDE, with only 1 class with the following code:

 class Test
 {
      public static void main(String[] args)
      {
          System.out.println(44);
      }
 }

When I try to run, it prints the following:

44

As we know, the classes in which lies the main method, must be public.

Then how come eclipse can compile and even run this program?

Upvotes: 0

Views: 695

Answers (1)

Sercan Ozdemir
Sercan Ozdemir

Reputation: 4692

You are simply wrong:

class HelloWorldApp {
    public static void main(String[] args) {
        System.out.println("Hello World!"); // Display the string.
    }
}

This is a quote from here which points the oracle documentation.

Upvotes: 4

Related Questions