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

后端 未结 9 496
囚心锁ツ
囚心锁ツ 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

    What @Bombe said. I would add that to OO purists, the fact that the entry class is not instantiated is a misstep. The reason is the static main prevents someone from writing a family of main classes that share the same main() method written using a template method pattern.

    If Java had been written to instantiate the main class and invoke the main method, users would have enjoyed the benefits of inheritance and interfaces.

提交回复
热议问题