子类不允许世界运行 [英] Subclass not allowing world to run
本文介绍了子类不允许世界运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是初学者,在学校参加CompSci课程。本章是制作子类。然而,类是以某种方式导致程序终止。世界甚至不出现,也没有错误。 (我正在运行Eclipse)。
I am a beginner, taking a CompSci class in school. This chapter is making subclasses; however, The class is somehow causing the program to terminate. The world doesn't even appear, and there are no errors. (I am running Eclipse).
这是我的代码:
package karel;
import kareltherobot.*;
public class Race implements Directions
{
public static void main(String args[]) {
class Car extends UrRobot
{ public Car(int street, int avenue, Direction direction, int beepers)
{super(5, 5, East, infinity);
}
public void turnAround()
{
turnLeft();
turnLeft();
}
public void turnRight()
{
turnLeft();
turnLeft();
turnLeft();
}
}
{
World.setVisible(true);
World.showSpeedControl(true);
}
{
Car kar = (Car) new UrRobot(5, 5, East, infinity);
kar.move();
kar.turnLeft();
kar.move();
kar.turnAround();
kar.move();
kar.turnRight();
}
}
}
b $ b
有没有办法让这个程序不会错误终止?
Is there a way to get this program to not error to termination?
推荐答案
/ p>
Try the following.
import kareltherobot.*;
public class Race implements Directions
{
public Race(){
}
public static void main(String args[]) {
class Car extends UrRobot
{
public Car(int street, int avenue, Direction direction, int beepers)
{
super(street, avenue, direction, beepers);
}
public void turnAround()
{
super.turnLeft();
super.turnLeft();
}
public void turnRight()
{
super.turnLeft();
super.turnLeft();
super.turnLeft();
}
}
World.setVisible(true);
World.showSpeedControl(true);
Car kar = new Car(5, 5, East, 100);
kar.move();
kar.turnLeft();
kar.move();
kar.turnAround();
kar.move();
kar.turnRight();
}
}
这篇关于子类不允许世界运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文