我是靠谱客的博主 激昂樱桃,这篇文章主要介绍编写代码模拟手机与SIM卡的组合关系,现在分享给大家,希望可以做个参考。

  1. public class SIM {  
  2. long number;  
  3. SIM(long number){  
  4.     this.number = number;  
  5. }  
  6. long getNumber() {  
  7.     return number;  
  8. }  
  9. }  
  10.   
  11. public class phone {  
  12. SIM sim;//声明对象  
  13. void setSIM(SIM card) {  
  14.     sim = card;  
  15. }  
  16. long lookNumber() {  
  17.     return sim.getNumber();  
  18. }  
  19.   
  20. }  
  21.   
  22. public class shouji {  
  23.   
  24.     public static void main(String[] args) {  
  25. SIM simOne = new SIM(18375431234L);//为对象分配实体  
  26. phone mobile = new phone();  
  27. mobile.setSIM(simOne);//调用方法setsim  
  28. System.out.println("手机号码:"+mobile.lookNumber());  
  29. SIM simTwo = new SIM(18375432345L);  
  30. mobile.setSIM(simTwo);  
  31. System.out.println("手机号码更换为:"+mobile.lookNumber());  
  32.     }  
  33. }  

最后

以上就是激昂樱桃最近收集整理的关于编写代码模拟手机与SIM卡的组合关系的全部内容,更多相关编写代码模拟手机与SIM卡内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(44)

评论列表共有 0 条评论

立即
投稿
返回
顶部