java _个人信息

 

interface Info1{
 
}
class Contact implements Info1{
 private String address;
 private String telphone;
 private String zipcode;
 public Contact (String address, String telphone,String zipcode){
  this.setAddress(address);
  this.setTelphone(telphone);
  this.setZipcode(zipcode);
  
 }
 public void setAddress(String address){
  this.address=address;
  }
 public String getAddress(){
  return address;
 }
 public String getTelphone(){
  return telphone;
 }
 public String getZipcode(){
  return zipcode;
 }
 public void setTelphone(String telphone){
  this.telphone=telphone;
 }
 public void setZipcode(String zipcode){
  this.zipcode=zipcode;
 }
 public String toString(){
  
  return "联系方式:"+"\n"+
    "\t-联系电话:"+this.telphone+"\n"+
    "\t-联系地址:"+this.address+"\n"+
    "\t-邮政编码:"+this.zipcode;
 }
}
class Introduction implements Info1{
 private String name;
 private String sex;
 private int age;
 public Introduction(String name ,String sex,int age){
  this.setName(name);
  this.setSex(sex);
  this.setAge(age);
 }
 public String getName(){
  return name ;
 }
 public String getSex(){
  return sex;
 }
 public int getAge(){
  return age ;
 }
 public void setName(String name){
  this.name=name;
 }
 public void setSex(String sex){
  this.sex=sex;
 }
 public void setAge(int age){
  this.age=age;
 }
public String toString(){
  
  return "基本信息:"+"\n"+
    "\t-姓名:"+this.name+"\n"+
    "\t-性别:"+this.sex+"\n"+
    "\t-年龄:"+this.age;
 }
}
class Person<T extends Info1>{
 private T info;
 public Person(T info){
  this.setInfo(info);
 }
 public T getInfo(){
  return info;
 }
 public void setInfo(T info){
  this.info=info;
 }
 public String toString(){
  return this.info.toString();
 }
}
public class GenericsDemo32 {
 public static void main(String args[]){
  Person<Contact> per=null;
  per=new Person<Contact>(new Contact("北京市","01051283346","100088"));
  System.out.println(per);
 }

}

阅读更多
上一篇经典进程问题:生产者与消费者
下一篇java-泛型的应用
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭
关闭