zoukankan      html  css  js  c++  java
  • java代码实现通讯录实例,我不知道这有什么用。,

    运行显示:

    Friend:zl,Address:武大樱花美
    Colleagues:蔡依林,Department:麻城市人民政府

    题目:

    1.任务描述

    完善上面通讯录名片的例子。

    2.技能要点

    掌握类继承的方法与技巧。

    package com.jay;
    
    //实现通讯录  定义一个ton类。表示名片,命名有误啊
    //姓名年龄///源文件:ton.java
    public class ton {
    	String name;
    	String sex;
    	String tel;
    
    	public ton() {
    	}
    
    	public ton(String name, String sex) {
    		this.name = name;
    		this.sex = sex;
    	}
    
    	public void setName(String a) {
    		this.name = a;
    
    	}
    
    	public String getName() {
    		return name;
    	}
    
    	public void setSex(String b) {
    		this.sex = b;
    	}
    
    	public String getSex() {
    		return sex;
    	}
    
    	public void setTel(String t) {
    		this.tel = t;
    
    	}
    
    	public String getTel() {
    		return tel;
    	}
    
    }
    
    2.FriendCard
    package com.jay;
    
    public class FriendCard extends ton {
    	String address;// 子类新增属性
    
    	public FriendCard(String name) {
    		address = name;
    	}
    
    	public void setAddress(String a) {
    		address = a;
    	}
    
    	public String getAddress() {
    		return address;
    	}
    
    }
    
    3.ColleaguesCard
    
    package com.jay;
    
    public class ColleaguesCard extends ton
    {
    	String department;
    	public ColleaguesCard(String name){
    		this.name=name;
    	}//这里的构造方法提供了后面直接在创建对象时赋初值
    	public void setDepartment(String department){
    		this.department=department;
    		
    	}public String getDepartment(){
    		return department;
    	}
    }
    
    
    4.Test.java
    
    package com.jay;
    
    public class ColleaguesCard extends ton
    {
    	String department;
    	public ColleaguesCard(String name){
    		this.name=name;
    	}//这里的构造方法提供了后面直接在创建对象时赋初值
    	public void setDepartment(String department){
    		this.department=department;
    		
    	}public String getDepartment(){
    		return department;
    	}
    }
    

      

  • 相关阅读:
    [Hapi.js] Route parameters
    [Hapi.js] Logging with good and good-console
    [Hapi.js] Up and running
    [Unit Testing] Directive testing, require parent controller
    数学-盲点题:九个点用四条直线连起来
    汉语-词语-思维:思维方法
    汉语-词语-思维:思维方式
    汉语-词语:思维
    思考方式-数学-盲点题:盲点题
    摄像机-哈苏:哈苏
  • 原文地址:https://www.cnblogs.com/langlove/p/3439821.html
Copyright © 2011-2022 走看看