运行显示:
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; } }