实例化

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.效果图:
在这里插入图片描述
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值