12 应用举例


用类封装手机的基本属性和功能,要求手机既可以使用移动公司的SIM卡也可以使用联通公司SIM卡(可以使用任何公司提供的SIM卡)

public abstract class SIM {
public abstract void setNumber(String n);
public abstract String giveNumber();
public abstract String giveCorpName();
}
public class SIMOfChinaUnicom extends SIM {
String number;
public void setNumber(String n){
number=n;
}
public String giveNumber(){
return number;
}
public String giveCorpName(){
return "中国联通";
}
}
public class SIMOfChinaMobile extends SIM {
String number;
public void setNumber(String n){
number=n;
}
public String giveNumber(){
return number;
}
public String giveCorpName(){
return "中国移动";
}
}
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());
}
}

public class Application {
public static void main(String[] args) {
MobileTelephone telephone=new MobileTelephone();
SIM sim=new SIMOfChinaMobile();
sim.setNumber("13856432");
telephone.useSIM(sim);
telephone.showMess();
sim =new SIMOfChinaUnicom();
sim.setNumber("1309765437");
telephone.useSIM(sim);
telephone.showMess();
}

}

TRANSLATE with x

English

Arabic Hebrew Polish
Bulgarian Hindi Portuguese
Catalan Hmong Daw Romanian
Chinese Simplified Hungarian Russian
Chinese Traditional Indonesian Slovak
Czech Italian Slovenian
Danish Japanese Spanish
Dutch Klingon Swedish
English Korean Thai
Estonian Latvian Turkish
Finnish Lithuanian Ukrainian
French Malay Urdu
German Maltese Vietnamese
Greek Norwegian Welsh
Haitian Creole Persian  

12 应用举例


 

TRANSLATE with

COPY THE URL BELOW

Back

EMBED THE SNIPPET BELOW IN YOUR SITE

Enable collaborative features and customize widget: Bing Webmaster Portal
Back

原创文章,作者:3628473679,如若转载,请注明出处:https://blog.ytso.com/271437.html

(0)
上一篇 2022年7月4日
下一篇 2022年7月4日

相关推荐

发表回复

登录后才能评论