Karel如何在没有“主要”的情况下运行方法? [英] How does Karel run without "main" method?

查看:173
本文介绍了Karel如何在没有“主要”的情况下运行方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在卡雷尔机器人的计划中运行,因为它没有使用main()方法。相反,它使用了run()方法:

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;

public class CollectNewspaperKarel extends Karel { 
  public void run() { 
    move(); 
  } 
}

它是如何运作的?

推荐答案

实际的主要方法是在其他地方。例如,在 KarelRunner类中。当java执行程序时,它实际上是在run类中执行main方法。从该转轮代码调用您自己的run方法。

The actual main method is somewhere else. For example, in the KarelRunner class. When java executes the program, it's actually executing the main method in the runner class. Your own run method is called from that runner code.

这篇关于Karel如何在没有“主要”的情况下运行方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆