package MobileTelephone;
public class MobileTelephone {
SIM card;
public void useSIM(SIM card)
{
this.card=card;
}
public void showMess()
{
System.out.println("使用的卡是:"+card.giveCorpName()+"提供的。");
System.out.println("手机号码是:"+card.giveNumber());
}
}
package MobileTelephone;
public abstract class SIM { //虚基类
public abstract void setNumber(String n);
public abstract String giveNumber();
public abstract String giveCorpName();
}
package MobileTelephone;
public class SIMOFChinaMobile extends SIM{
String number;
public void setNumber(String n)
{
number=n;
}
public String giveNumber()
{
return number;
}
public String giveCorpName()
{
return "中国移动";
}
}
package MobileTelephone;
public class SIMOFChinaUnicom extends SIM {
String number;
public void setNumber(String n)
{
number=n;
}
public String giveNumber()
{
return number;
}
public String giveCorpName()
{
return "中国联通";
}
}
package MobileTelephone;
public class Application {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
MobileTelephone telephone = new MobileTelephone();
SIM sim;
sim = new SIMOFChinaMobile();
sim.setNumber("13836552888");
telephone.useSIM(sim);
telephone.showMess();
sim = new SIMOFChinaUnicom();
sim.setNumber("15677021080");
telephone.useSIM(sim);
telephone.showMess();
}
}