英文:
Why is my System.out.println not working? Also this is not the main class and when i try to access it from the main class i don't get the output
问题
以下是翻译好的代码部分:
public class Init{
private String clientName;
private String clientNumber;
private double balance;
public Init(ASCIIDataFile file){
clientNumber = file.readString();
clientName = file.readString();
balance = file.readDouble();
}
public String getClientName(){
System.out.println(clientName); // `not working`
return clientName;
}
}
英文:
the code isn't giving the output
public class Init{
private String clientName;
private String clientNumber;
private double balance;
public Init(ASCIIDataFile file){
clientNumber = file.readString();
clientName = file.readString();
balance = file.readDouble();
}
public String getClientName(){
System.out.println(clientName); // `not working`
return clientName;
}
}
答案1
得分: -2
你的构造函数中缺少 this.
,因此在 getClientName()
中的 clientName
为空。
你的构造函数应该像这样:
public Init(ASCIIDataFile file){
this.clientNumber = file.readString();
this.clientName = file.readString();
this.balance = file.readDouble();
}
英文:
You are missing this.
in constructor therefore clientName
in getClientName()
is empty
Your constructor should be like this:
public Init(ASCIIDataFile file){
this.clientNumber = file.readString();
this.clientName = file.readString();
this.balance = file.readDouble();
}
专注分享java语言的经验与见解,让所有开发者获益!
评论