• Welcome to Valhalla Legends Archive.
 

non-static variable error

Started by Mr. Neo, March 19, 2005, 10:54 PM

Previous topic - Next topic

Mr. Neo


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?

iago

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.
This'll make an interesting test for broken AV:
QuoteX5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*


Mr. Neo

Thank you for clarifying that.