gpt4 book ai didi

java - 输出显示空值。如何解决

转载 作者:行者123 更新时间:2023-12-01 06:41:31 25 4
gpt4 key购买 nike

我有三门课:

CustomerData.java

import java.util.Date;
public class CustomerData
{
private String FirstName;
private String LastName;
private int TaxId;
private String HomePhone;
private String WorkPhone;
private String HomeAddress;
private Date Dob;
private String EmployerName;
private boolean isEmployed;
private String ProDescription;
private String IsSameAsPrevious;

public String getFirstName() {
return FirstName;
}
public void setFirstName(String firstName) {
FirstName = firstName;
}
public String getLastName() {
return LastName;
}
public void setLastName(String lastName) {
LastName = lastName;
}
public int getTaxId() {
return TaxId;
}
public void setTaxId(int taxId) {
TaxId = taxId;
}
public String getHomePhone() {
return HomePhone;
}
public void setHomePhone(String homePhone) {
HomePhone = homePhone;
}
public String getWorkPhone() {
return WorkPhone;
}
public void setWorkPhone(String workPhone) {
WorkPhone = workPhone;
}
public String getHomeAddress() {
return HomeAddress;
}
public void setHomeAddress(String homeAddress) {
HomeAddress = homeAddress;
}
public Date getDob() {
return Dob;
}
public void setDob(Date dob) {
Dob = dob;
}
public String getEmployerName() {
return EmployerName;
}
public void setEmployerName(String employerName) {
EmployerName = employerName;
}
public boolean isEmployed() {
return isEmployed;
}
public void setEmployed(boolean isEmployed) {
this.isEmployed = isEmployed;
}
public String getProDescription() {
return ProDescription;
}
public void setProDescription(String proDescription) {
ProDescription = proDescription;
}
public String getIsSameAsPrevious() {
return IsSameAsPrevious;
}
public void setIsSameAsPrevious(String isSameAsPrevious) {
IsSameAsPrevious = isSameAsPrevious;
}

}

MainCntrlr.java

public class MainCntrlr {
public static void main(String[] args)
{
CustomerData customerData=new CustomerData();
customerData.setFirstName("RAVI");
customerData.setLastName("Shekhar");
customerData.setHomePhone("123456789");
customerData.setWorkPhone("1256554634");
customerData.setHomeAddress("Banagalore");
customerData.setEmployerName("ABc");
customerData.setProDescription("New Produtc");
customerData.setTaxId(1233434343);



ContrOne ctr=new ContrOne();
ctr.displayInformation();
}
}

ContrOne.java

import com.blr.CustomerData;
public class ContrOne
{
public void displayInformation()
{
CustomerData cd=new CustomerData();
System.out.println("displaying customer Info");

System.out.println(cd.getFirstName());
System.out.println(cd.getLastName());
System.out.println(cd.getHomePhone());
System.out.println(cd.getWorkPhone());
System.out.println(cd.getEmployerName());
System.out.println(cd.getProDescription());
System.out.println(cd.getDob());
System.out.println(cd.getTaxId());


}
}

输出是:

displaying customer Info
null
null
null
null
null
null
null
0

最佳答案

在方法 ContrOne.displayInformation() 中,您创建一个新的 new CustomerData() 对象。因此它没有正确初始化。也许您想将 customerDatamain 方法传递到 displayInformation

关于java - 输出显示空值。如何解决,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5521888/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com