Hi everyone i am new to Java and OOP so please be gentle with me, i will try to make this question make as much sense as i can. I have a method that takes arraylists and i want to get elements from that arraylist and set them to a new object under my Student class
i think the issue is where i am making the object Student stu1 = new Student();. Do i have to do this in every method to be able to access it? where should i create this object so i can add to it from the addStudent method and retrieve info from it in other methods?
public void addStudent(ArrayList<String> id, ArrayList<String> firstName,ArrayList<String> lastName) {
// setting the stu1 objects id firstname and lastname variables
Student stu1 = new Student();
stu1.setId(id.get(0));
stu1.setFirstname(firstName.get(0));
stu1.setLastname(lastName.get(0));
and in my student class
public class Student {
String id;
String firstname;
String lastname;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getFirstname() {
return firstname;
}
public void setFirstname(String firstname) {
this.firstname = firstname;
}
public String getLastname() {
return lastname;
}
public void setLastname(String lastname) {
this.lastname = lastname;
}
public void saystuff() {
System.out.println(id + firstname + lastname);
when call staystuff() in my main method it returns null null null, obviously i am doing something wrong setting the variables or it is because i have to make the new stu1 object again under the main method? how can i access stu1 from the static main method because it was created in a non static method.
main method
```
public static void main(String[] args) throws IOException {
Student stu1 = new Student();
stu1.saystuff();