Java 代码封装客户信息 (ID、姓名、公司名称)
以下是一个返回客户 ID,客户姓名,公司名称,一共六个字段数据的 Java 代码:
public class Customer {
private String customerId;
private String customerName;
private String companyName;
public Customer(String customerId, String customerName, String companyName) {
this.customerId = customerId;
this.customerName = customerName;
this.companyName = companyName;
}
public String getCustomerId() {
return customerId;
}
public void setCustomerId(String customerId) {
this.customerId = customerId;
}
public String getCustomerName() {
return customerName;
}
public void setCustomerName(String customerName) {
this.customerName = customerName;
}
public String getCompanyName() {
return companyName;
}
public void setCompanyName(String companyName) {
this.companyName = companyName;
}
@Override
public String toString() {
return 'Customer{' +
'customerId=' + customerId + '\'
+ ', customerName=' + customerName + '\'
+ ', companyName=' + companyName + '\'
+ '}';
}
}
使用方法:
Customer customer = new Customer('001', 'John Doe', 'ABC Inc.');
System.out.println(customer.getCustomerId());
System.out.println(customer.getCustomerName());
System.out.println(customer.getCompanyName());
原文地址: https://www.cveoy.top/t/topic/mJ4r 著作权归作者所有。请勿转载和采集!