簡體   English   中英

為什么我的 System.out.println 不工作? 這也不是主要的 class,當我嘗試從主要的 class 訪問它時,我沒有得到 output

[英]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

代碼沒有給出 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;  
  }
}

你錯過了this. 在構造函數中,因此getClientName()中的clientName為空

你的構造函數應該是這樣的:

    public Init(ASCIIDataFile file){

        this.clientNumber = file.readString();
        this.clientName = file.readString();
        this.balance = file.readDouble();
    } 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM