-1
这是我的代码。 在我的主要功能中,我已经包含一个构造函数。 我有多个构造函数在我的客户端类有构造函数问题
public class Client {
private String name = "", username = "", ClientID = "", password = "";
Client[] account = new Client[100];
public Client() {
}
public Client(String name, String username) {
// will have generated function for ClientID and also Password
account[clientCount] = new Client();
account[clientCount].setName(name);
account[clientCount].setUsername(username);
account[clientCount].setPassword(password);
account[clientCount].setClientID(CID);
}
public Client(String name, String username, String password, String ClientID) {
this.name = name;
this.username = username;
this.password = password;
this.ClientID = ClientID;
}
public static void main(String[] args) {
if (selection == 1) {
Client client = new Client(); // object created called "client"
name = JOptionPane.showInputDialog("Account Status: Admin\n" + "Please Enter Client Name: ");
username = JOptionPane.showInputDialog("Account Status: Admin\n" + "Please Enter Client Userame: ");
Client CLIENT = new Client(name, username);
JOptionPane.showMessageDialog(null,
CLIENT.account[Client.clientCount].getName() + "\n" + CLIENT.account[Client.clientCount].getUsername() + "\n"
+ CLIENT.account[Client.clientCount].getPassword() + "\n" + CLIENT.account[Client.clientCount].getClientID());
}
if (selection == 2) {
// at here, unable to access to CLIENT object, what can I do access
// CLIENT object to here. Or copy the same object into the other new
// object
for (int i = 0; i <= Client.clientCount; i++) {
System.out.println(CLIENT.account[i].getName());
}
}
}
}
而这个问题是......? – Keppil
我无法访问“if(选择== 1)”之外的CLIENT对象 – JaxLee
加入guys,wtf?重新说出Q并请格式化答案。啧。 – Shiki