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;
    	}
    }
    

      

  • 相关阅读:
    hdu4734 F(x)
    hdu2089 不要62 两解
    luogu2602 [ZJOI2010]数字计数 两解
    lemon
    UVA1218 完美的服务 Perfect Service
    luogu HNOI2003消防局的设立
    uva10891 game of sum
    uva10635 Prince and Princess
    UVA1394 And Then There Was One
    uva10003切木棍
  • 原文地址:https://www.cnblogs.com/langlove/p/3439821.html
Copyright © 2011-2022 走看看