Background:
I’m creating a basic download centre on a concurrent server.
I create file objects in the Server class under a main method
File[] files = {
new File("1. Program", "myProgram.jar"),
new File("2. Image", "myPicture.jpg"),
new File("3. Book", "myBook.txt")};
This references to the File class where I create constructors and getters.
class File {
private String option;
private String fileName;
public File(String option, String fileName) {
this.option = option;
this.fileName= fileName;
}
public String getOption() {
return option;
}
public String getFileName() {
return fileName;
}
public void getFileOptions(File[] files) {
for (File f : files) {
System.out.printf("The option is %s\n", f.getOption());
}
}
}
I am attempting to call the getFileOptions method from my ServerState class.
theOutput= File.getFileOptions(files);
The output is a string that is returned to a client.
My IDE says that (files) cannot be found. Any ideas where I’m going wrong? Cam I not return results to a class where the object wasn’t initially created?
OK so I have moved the File objects into the
ServerState classand access the options usingString theOutput = files[0].toString() + files[1].toString() + files[2].toString();by calling atoString()method from theFile classthat also contain the object constructors, getters and setters.