I am creating a simple Jave console application. So I am using few classes in different files. I need to set some parameters for the class instance and retrieve it later. but it gives me following error. Please help me to solve it.
Main Class
public class Main {
private Student student = new Student();
public static void main(String[] args) {
student.setName("John");
//Java: non-static variable student cannot be referenced from a static context
}
}
Student Class
public class Student {
private String name;
public String getName() {
return name;
}
public void setName(String name) {
name = name;
}
}
How can I avoid this issue ? Please help