Why the main program in Java is put into a class?

后端 未结 9 480
囚心锁ツ
囚心锁ツ 2020-12-28 17:37

Why does the main method have to be put into a class? I understand the main ideas of OOP but I cannot get why the main program is defined within a class. Will such a class i

9条回答
  •  情话喂你
    2020-12-28 17:59

    It does simplify the design of the virtual machine. Since virtual machine already knows how to run a static method of a class then it can treat the main method just as any other static method.

    If you put the main method in any other construct other than a class then the VM has to be modified to know about another construct complicating things even more.

提交回复
热议问题