jcreator和cmd下的运行结果为什么不一样呀

来源:百度知道 编辑:UC知道 时间:2024/06/07 03:51:52
我有一个程序,如下:
//定义接口Power
interface Power {
void volt(int volt);
}

//定义接口Output
interface Output {
void outputWave(String msg);
}

//定义接口Txt
interface Txt {
int SIZE = 10;
String getTxt(String msg);
}

//实现Power, Output接口
class Oscillograph implements Power, Output {

public void volt(int volt) {
System.out.println("the volt is "+volt);
}

public void outputWave(String msg) {
System.out.println("the output wave is "+msg);
}
}

//实现Txt接口
class TextMessage implements Txt {

public String getTxt(String msg) {
if (msg.length() > SIZE)
return msg.substring(0, SIZE);
else
return msg;
}
}

public class InterfaceUse {
public static void main(String[] args) {

既然Oscillograph 实现了interface Output ,就必须实现它的方法outputWave,你把它注释了是通不过的。一是因为实现某个接口就必须实现它的方法,二是你在主函数中使用了outputWave方法。你说在JCreate中通过了,我猜可能是你没有重新编译。