If i create an object in Class1 and save some data in that object in Class1, how can i access that same data in Class2? Here's a code sample that should clarify my situation:
Class1.java:
public class Class1 implements Runnable {
public ClientArray ca;
public Class1(int port) throws IOException {
ca = new ClientArray();
Client client = new Client(socket);
ca.setArraySize();
ca.addClient(client);
}
Class2.java:
protected void doInSession() {
//need to access that same ClientArray ca here that i created in Class1!
System.out.println(ca.getClient() + "clietttttttttttttt");
}
ClientArray.java:
public class ClientArray {
Client[] ClientArray;
public void ClientArray() {
}
public void setArraySize() {
System.out.println("new ca");
ClientArray = new Client[100];
}
public void addClient(Client client) {
ClientArray[0] = client;
}
public Client getClient() {
System.out.println(ClientArray[0].getSocket() + " aaaaaaaaaaaaaaaaaa");
return ClientArray[0];
}
}