1.new-class
package com.sict.gm.entity;
public class person {
private String name;//姓名
private String address;//来电地址
private String number;//号码
private category category;
public String getNumber() {
return number;
}
public void setNumber(String number) {
this.number = number;
}
public category getCategory() {
return category;
}
public void setCategory(category category) {
this.category = category;
}
public person(){
}
public person(String name,String address,String number,category category){
this.name=name;
this.address=address;
this.number=number;
this.category=category;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getVersion() {
return number;
}
public void setVersion(String version) {
this.number = version;
}
public String tostring(){
return "姓名:"+name+"\t"+"地址:"+address+"\t"+"号码:"+number+"\t"+ "类型:"+category.tostring();
}
}
2.再new-class
package com.sict.gm.entity;
public class category {
private String version1;
private String version2;
public category(){
}
public category(String version1,String version2){
this.version1=version1;
this.version2=version2;
}
public String getVersion1() {
return version1;
}
public void setVersion1(String version1) {
this.version1 = version1;
}
public String getVersion2() {
return version2;
}
public void setVersion2(String version2) {
this.version2 = version2;
}
public String tostring(){
return version1+">"+version2;
}
}
3.编写测试类
package com.sict.gm;
import com.sict.gm.entity.category;
import com.sict.gm.entity.person;
public class Test {
public static void main(String[] args) {
// TODO Auto-generated method stub
category c1=new category();
c1.setVersion1("住宅");
c1.setVersion2("手机");
category c2=new category("住宅","手机");
person p1=new person("张三","山东济南","15666531150",c2);
person p2=new person("李永春","山东菏泽","15666531150",c1);
person p3=new person("王二麻子","山东潍坊","15666531150",c1);
person p4=new person("李四","山东泰安","15666531150",c1);
System.out.println(p1.tostring());
System.out.println(p2.tostring());
System.out.println(p3.tostring());
System.out.println(p4.tostring());
}
}
4.效果图: