错误发生在和public class ModemTester
下。我是编程新手和这本书,山姆在 24 小时内学习 Java,我正在经历这个练习,清单 10.2-5,我无法弄清楚。你们所有的专家都让我充满你的智慧^-^。谢谢你CableModem
DslModem
public class Modem {
int speed;
public void displaySpeed() {
System.out.println("Speed: " + speed);
}
}
public class CableModem extends Modem {
String method = "cable connection";
public void connect() {
System.out.println("Connecting to the Internet.....");
System.out.println("Using a " + method);
}
}
public class DslModem extends Modem {
String method = "DSL phone connection";
public void connect() {
System.out.println("Connecting to the Internet.....");
System.out.println("Using a " + method);
}
}
public class ModemTester {
public static void main(String[] args) {
CableModem surfBoard = new CableModem();
DslModem gateway = new DslModem();
surfBoard.speed = 500000;
gateway.speed = 400000;
System.out.println("Trying the cable modem:");
surfBoard.displaySpeed();
surfBoard.connect();
System.out.println("Trying the DSL modem:");
gateway.displaySpeed();
gateway.connect();
}
}