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(); } }
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)