Does every program in Java require a class?

后端 未结 6 1211
臣服心动
臣服心动 2020-12-16 02:19

Every Java program requires the presence of at least one class.

Is the above statement always true ?

6条回答
  •  没有蜡笔的小新
    2020-12-16 02:55

    From the JVM's point of view; yes. From a programmers view point, it can be a Class or an Enum.

    public enum AAA {
    
        AAA;
    
        public static void main(final String[] args) {
            System.out.println("H");
        }
    
    }
    

    EDIT: Even if you have a class with empty main method, there are a lot of core classes which work behind the scene to just run the "empty" class of yours. A list of those classes (around 200 from the java.* package) can be viewed by setting the -verbose:class JVM parameter.

提交回复
热议问题