work188.java
package test10;
public class work188
{
public static void main(String[] args)
{
CableModem01 surfBoard = new CableModem01();
DslModem gateway = new DslModem();
surfBoard.speed = 500000;
gateway.speed = 400000;
System.out.println("尝试连接:");
surfBoard.displaySpeed();
surfBoard.connect();
System.out.println("尝试连接:");
gateway.displaySpeed();
gateway.connect();
}
}
class Modem01
{
int speed;
public void displaySpeed()
{
System.out.println("速率:" + speed );
}
}
class CableModem01 extends Modem01
{
String method = "电缆调制解调器";
public void connect()
{
System.out.println("使用" + method);
System.out.println("正在连接互联网...");
}
}
class DslModem extends Modem01
{
String method = "数字线路调制解调器";
public void connect()
{
System.out.println("使用" + method);
System.out.println("正在连接互联网...");
}
}