Hello world works but then gets error that there's no main?

前端 未结 6 597
星月不相逢
星月不相逢 2020-12-09 09:57

I have the following simple hello world in Java:

class A {
    static {
        System.out.println(\"Hello world\");
    }
}

It works as ex

6条回答
  •  北海茫月
    2020-12-09 10:42

    Forget the static block, and do it like this:

    public static void main(String[] args) {
        System.out.println("Hello, world!");
    }
    

提交回复
热议问题