zoukankan      html  css  js  c++  java
  • 抽象类实验:SIM卡抽象

    抽象SIM:

    package sim_package;
    
    public abstract class SIM {
    	public abstract String giveNumber();
    	public abstract String giveCorpName();
    	public abstract void setNumber(String n);
    }
    

    SIM子类:

    package sim_package;
    
    public class SIMOFChinaMobile extends SIM{
    	String phonenumber;
    	public SIMOFChinaMobile(){
    		phonenumber="";
    	}
    	public SIMOFChinaMobile(String phonenumber){
    		this.phonenumber=phonenumber;
    	}
    	 public String giveNumber(){
    		 return phonenumber;
    	 }
    	 public String giveCorpName(){
    		 return "中国移动";
    	 }
    	 public void setNumber(String phonenumber){
    		 this.phonenumber=phonenumber;
    	 }
    }

    SIM子类:

    package sim_package;
    
    public class SIMOFChinaUnicom extends SIM {
    	String phonenumber;
    	public SIMOFChinaUnicom(){
    		phonenumber="";
    	}
    	public SIMOFChinaUnicom(String phonenumber){
    		this.phonenumber=phonenumber;
    	}
    	 public String giveNumber(){
    		 return phonenumber;
    	 }
    	 public String giveCorpName(){
    		 return "中国联通";
    	 }
    	 public void setNumber(String phonenumber){
    		 this.phonenumber=phonenumber;
    	 }
    }
    

    手机类:

    package Mobile_telephone;
    import sim_package.*;
    public class Mobiletelephone {
    	SIM card;
    	public Mobiletelephone(){
    		
    	}
    	public Mobiletelephone(SIM card){
    		this.card=card;
    	}
    	public void useSIM(SIM card){
    		System.out.println("运营商:"+card.giveCorpName());
    		System.out.println("手机号:"+card.giveNumber());
    	}
    }

    主程序:

    import Mobile_telephone.*;
    import sim_package.*;
    public class Application {
    
    	public static void main(String[] args) {
    		SIM sim=new SIMOFChinaUnicom();
    		sim.setNumber("13887656432");
    		Mobiletelephone phone=new Mobiletelephone();
    		phone.useSIM(sim);
    		sim=new SIMOFChinaMobile();
    		sim.setNumber("13097656437");
    		phone.useSIM(sim);
    	}
    
    }
    


  • 相关阅读:
    asp window.showModalDialog浏览器不兼容的解决方案
    JavaScript倒计时算法(计算剩余多少天)实现
    (全程图解)Axure RP8.0安装教程
    HTML通过超链接传递参数到JSP页面-html与jsp交互
    JavaWeb中登录验证码生成
    PowerDesigner16.5安装教程
    前台正则的使用
    稀疏算法Sparse
    ajax请求超时解决方案
    修改默认select样式
  • 原文地址:https://www.cnblogs.com/WALLACE-S-BOOK/p/9732337.html
Copyright © 2011-2022 走看看