JAVA.5.12 SIM 手机卡 问题

JAVA.5.12 SIM 手机卡 问题,第1张

SIM.java
public abstract class SIM {
    public abstract void setNumber(String n);
    public abstract String giveNumber();
    public abstract String giveCorpName();
}
 
MobileTelephone.java
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());
    }
}
SIMOFChinaMobile.java
public class SIMOFChinaMobile extends SIM{
    String number;
    public void setNumber (String n){
        number = n;
    }
    public String giveNumber(){
        return number;
    }
    public String giveCorpName(){
        return"中国移动";
    }
}
SIMOFChinaUnicom.java
public class SIMOFChinaUnicom extends SIM{
    String number;
    public void setNumber(String n){
        number = n;
    }
    public String giveNumber(){
        return number;
    }
    public String giveCorpName(){
        return"中国联通";
    }
}
Application.java
public class Application {
    public static void main(String[] args) {
        MobileTelephone telephone = new MobileTelephone();
        SIM sim = new SIMOFChinaUnicom();
        sim.setNumber("13887656432");
        telephone.useSIM(sim);
        telephone.showMess();
        sim = new SIMOFChinaUnicom();
        sim.setNumber("13097656437");
        telephone.useSIM(sim);
        telephone.showMess();
    }
}

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/800569.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-07
下一篇 2022-05-07

发表评论

登录后才能评论

评论列表(0条)

保存