Java 使用子类和超类的亡灵和吸血鬼程序
我的不死族超类和吸血鬼子类代码如下 当我尝试在一个叫coderunner的网站上运行它时;这个网站没有给我主要功能,这个问题也没有给我一个示例输出 我得到以下错误:Java 使用子类和超类的亡灵和吸血鬼程序,java,subclass,superclass,Java,Subclass,Superclass,我的不死族超类和吸血鬼子类代码如下 当我尝试在一个叫coderunner的网站上运行它时;这个网站没有给我主要功能,这个问题也没有给我一个示例输出 我得到以下错误: class Undead{ protected String food; protected String comesOut; Undead(){ } Undead(String f){ food = f; } public void setFood(String f){
class Undead{
protected String food;
protected String comesOut;
Undead(){
}
Undead(String f){
food = f;
}
public void setFood(String f){
food = f;
}
public String getFood(){
return food;
}
public void eats(){
System.out.println("The undead eats "+ food);
}
public void comesOut(){
System.out.println("The undead can come out" + comesOut);
}
}
class Vampire extends Undead {
private String name ;
Vampire(){
}
Vampire(String n){
name = n;
}
Vampire(String n, String f){
name = n;
food = f;
}
public void setName(String n){
name = n;
}
public String getName(){
return name;
}
public void eats(){
System.out.println(name + "drinks" + food);
}
public void comesOut(){
System.out.println(name + "comes out"+ comesOut);
}
}
我在ecclipse上尝试了这个,似乎没有任何错误。知道问题出在哪里吗
编辑:
您需要添加一个名为“setComesOut”的方法,该方法将字符串作为参数。此函数应将不死生物变量“comesOut”设置为给定的任何参数,类似于“setName”或“setFood”方法。您的代码是否符合给定的要求?具体要求是什么?亡灵类应该有一个公共的
setComesOut(字符串文本)
方法吗?旁注:你们并没有像你们应该的那个样使用超级构造函数。你们并没有按照你们的作业指导去做。投票结束只是一个小错误。请你详细说明我没有遵循的内容和我做错的内容。你的说明告诉你创建你没有遵循的方法——遵循说明,这就是全部内容。非常感谢。对不起,我是个白痴,没有阅读说明书。
Syntax Error(s)
__Tester__.java:62: cannot find symbol
symbol : method setComesOut(java.lang.String)
location: class Undead
u.setComesOut("at anytime");
^
__Tester__.java:69: cannot find symbol
symbol : method setComesOut(java.lang.String)
location: class Vampire
v1.setComesOut("at night");
^
2 errors
The superclass Undead contains
A protected String variable food.
A private String variable comesOut.
Two constructors
- one takes no parameter.
- one takes a String parameter food and assigns this value to the variable food.
A public method setFood() that takes a String parameter and sets the variable food to the parameter's value.
A public method getFood() that returns the value of food.
A public method eats() that prints "The undead eats [food]".
A public method comesOut() that prints "The undead can come out [comesOut]".
The subclass Vampire contains
A private String variable name.
Three constructors.
- one takes no parameter.
- one takes a String parameter name and assigns this value to the variable name.
- one takes two String parameters name and food and sets the variables name and food to these values.
A public setName() method that takes a String parameter and sets name to the value of this parameter.
A public getName() method that returns the value of name.
A public method eats() that prints "[name] drinks [food]".
A public method comesOut() that prints "[name] comes out [comesOut]"