What is the role of the class in which the main method is wrapped?

Stack Overflow :

As we know that the main method is the entry point of the java program as described in the following resources:

Why main() method is needed in java main class?

Why should main be present in a Java class? [duplicate]

If this is the case then why we need to wrap the main method in the class if the main method is the entry point?

enter image description here

What is the role of the class which wraps the main method?

ernest_k :

In Java, there's no way to have a method without an enclosing type. You need a class, an interface, an enum, etc. to be able to declare and/or implement a method. This is just how it works.

Even when you start a Java program, you specify the name of the class containing the main method. You don't just run arbitrary statements.

In other words it's about the program structure rather than about a specific role played by the class around the main method. And you can even use an interface instead of a class in recent versions of Java.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=111355&siteId=1