How does Karel run without “main” method?

前端 未结 5 1655
臣服心动
臣服心动 2021-01-21 20:34

I was wondering in the program like Karel the Robot runs because it does not used main() method. Instead it used run() method:

import stanford.karel.Karel;

publ         


        
5条回答
  •  太阳男子
    2021-01-21 21:01

    a "main" method is the starting point of every java program. What is going on with this class is that its not a java program by itself, is executed inside some type of framework (karel robot java implementation in this case), this frameworks off course have a "main" method but not this class, the framework knows how to load this class and execute his run method.

    This "programs" are frameworks designed to do a specialized type of programs, i don't know this "karel framework", but for example, when you program a java web application you write a "servlet" but you don't write a "main" method. There are some programs called "application servers" that off course have a "main" method and take this servlet class and execute for response to some http message.

提交回复
热议问题