public class First
{
public Second a = new Second();
public static void main(String[] args)
{
System.out.println("First: main");
a.Test();
}
}
How come when I try to call a.Test() I get a "non-static variable a cannot be referenced from a static context" error? If I change a to being a static variable, everything works out fine. Does this mean that static variables can only be accessed from within static methods?
Quote from: Mr. Neo on March 19, 2005, 10:54 PM
Does this mean that static variables can only be accessed from within static methods?
No, other way around. Non-static variables can only be accessed from non-static methods.
Thank you for clarifying that.