传递了错误的参数。爪哇

时间:2019-02-01 05:10:33

标签: java

我在将已分类的构造函数的值作为另一个类的对象传递时遇到问题。

public class Client {

   private String firstName;
   private String lastName;
   private long phoneNum;
   private String email;

   public Client (String firstName, String lastName, long phoneNum, String email) {  }
}

public class Account {

    private long accountNum;
    private double balance;
    private Client client = new Client(null, null, accountNum, null);
    private Random random = new Random();
 }

在Account类中,它是String,String,Long,String。它在帐户类中采用long值并将其放入Client参数。如何传递在Client类中指定的参数?

2 个答案:

答案 0 :(得分:1)

您的Account类应该是这样的:

public class Account {

    private long accountNum;
    private double balance;
    private Client client;
    private Random random = new Random();
    public Account(long accountNum){
         this.client = new Client(null, null, accountNum, null);
    }
 }

答案 1 :(得分:0)

在“客户”类中为客户添加吸气剂和吸气剂。

在“帐户”类中设置accountNum。

然后创建一个Client实例

Client client = new Client(null, null, accountNum, null);

然后在“帐户”类中,设置客户端。

public void setClient( Client client )
{
    this.client = client;
}