package com.classes;
/*
 * 功能:泛型的使用
 */
public class fanxing {
    public static  void  main(String args[]){
        contact con = new contact("15995716443","苏州市","500116");
        cperson<introduce> intro = null;
        intro = new cperson<introduce>(new introduce("小五", 9, "男"));
        System.out.println(intro);
        cperson<contact> cont;
        cont = new cperson<contact>(new contact("15995716443", "苏州相城区", "500121"));
        System.out.println(cont);
    }
}
//定义标识接口
interface info{
}
class cperson <T extends info>{
    T instance;
    public cperson(T instance){
        this.instance=instance;
    }
    public T getInstance() {
        return instance;
    }
    public void setInstance(T instance) {
        this.instance = instance;
    }
    public String toString(){
        return this.instance.toString();
    }
}
//定义人的基本信息并继承标识接口
class introduce implements info{
    String name;    //姓名
    int age;        //年龄
    String sex;     //性别
    public introduce(String name,int age,String sex){
        this.setName(name);
        this.setAge(age);
        this.setSex(sex);
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public int getAge() {
        return age;
    }
    public void setAge(int age) {
        this.age = age;
    }
    public String getSex() {
        return sex;
    }
    public void setSex(String sex) {
        this.sex = sex;
    }
    public String toString(){
        return(
                        "姓名:"+this.getName()+"\n"+
                        "年龄:"+this.getAge()+"\n"+
                        "性别:"+this.getSex()+"\n"
                    );
    }
}
//定义人的联系方式类并继承标识接口
class contact implements info{
    String tel=null;
    String address = null;
    String zipCode = null;
    public contact(String tel,String address,String zipCode){
        this.settel(tel);
        this.setAddress(address);
        this.setZipCode(zipCode);
    }
    public String gettel() {
        return tel;
    }
    public void settel(String tel) {
        this.tel = tel;
    }
    public String getAddress() {
        return address;
    }
    public void setAddress(String address) {
        this.address = address;
    }
    public String getZipCode(){
        return zipCode;
    }
    public void setZipCode(String zipCode) {
        this.zipCode = zipCode;
    }
    public String toString(){
        return(
                        "电话:"+this.gettel()+"\n"+
                        "地址:"+this.getAddress()+"\n"+
                        "邮编:"+this.getZipCode()+"\n"
                    );
    }
}