Here's my code, I'm trying to access e1,e2,e3 in my getData() method but it's not working. How do I get my second method to recognize the first ones but keeping the methods separate?
public class Model {
public Model() {
loadData();
}
public void loadData() {
Employee e1 = new Employee("John Smith", "California, PA.", "Dr. Robertson junior.");
Employee e2 = new Employee("Kyle Alston", "State College, PA.", "SmithTown");
Employee e3 = new Employee("Tommy Smith", "Baskeville, PA.", "Chicago");
}
public String getData(int n) {
if(n == 1){
return e1;
}
if(n == 2){
return e2;
}
if(n == 3){
return e3;
}
}
}
I tried Model data = new loadData().e1 but I don't think that works.
Thanks in advance. I'm not allowed to change the parameters.
loadData()method creates employees that all get lost when the method finishes executing.