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

      

  • 相关阅读:
    java的类继承(与c++对比)
    java的数据类型、自动拆装箱、字面量
    java中关键字static和final
    JVM之JIT
    java之JIT(Just in time)
    栈和堆
    C++中vector的使用
    canvas
    ajax笔记
    CSS笔记
  • 原文地址:https://www.cnblogs.com/langlove/p/3439821.html
Copyright © 2020-2023  润新知