一、面向对象案例分析一
1、编写并测试一个代表地址的Address类,地址有国家、省份、城市、街道、邮编等组成。并返回完整的地址信息。
package anli1_;
/**
* @ClassName : Address //类名
* @Description : 国家、省份、城市、街道、邮编等//描述
* @Author : *** //作者
* @Date: 2021-08-01 10:27 //日期
*/
public class Address {
private String country; //国家
private String province;//省份
private String city; //城市
private String street; //街道
private long Zipcode; //邮编
public Address(){
//无参列表
}
public Address(String country, String province, String city, String street, long zipcode) {
this.country = country;
this.province = province;
this.city = city;
this.street = street;
Zipcode = zipcode;
}
//setget方法
public String getCountry() {
return country;
}
public void setCountry(String country) {
this.country = country;
}
public String getProvince() {
return province;
}
public void setProvince(String province) {
this.province = province;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public String getStreet() {
return street;
}
public void setStreet(String street) {
this.street = street;
}
public long getZipcode() {
return Zipcode;
}
public void setZipcode(long zipcode) {
Zipcode = zipcode;
}
//返回字符串
@Override
public String toString() {
return "Address{" +
"country='" + country + '\'' +
", province='" + province + '\'' +
", city='" + city + '\'' +
", street='" + street + '\'' +
", Zipcode=" + Zipcode +
'}';
}
}
package anli1_;
/**
* @ClassName : testAdderss //类名
* @Description : 编写一个测试类 //描述
* @Author : *** //作者
* @Date: 2021-08-01 10:26 //日期
*/
public class testAdderss {
public static void main(String[] args) {
//对象实例化
Address address = new Address("中国","河北","石家庄","滹沱河",100100);
//输出
System.out.println(address.toString());
}
}
程序输出结果:
Address{
country='中国', province='河北', city='石家庄', street='滹沱河', Zipcode=100100}
二、面向对象案例分析二
2、定义并测试代表员工的Employee类,员工属性包括编号