Valhalla Legends Forums Archive | Java Programming | non-static variable error

AuthorMessageTime
Mr. Neo
[code]
public class First
{
public Second a = new Second();

public static void main(String[] args)
{
System.out.println("First: main");
a.Test();
}
}
[/code]

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?
March 20, 2005, 4:54 AM
iago
[quote author=Mr. Neo link=topic=10969.msg104615#msg104615 date=1111294497]
Does this mean that static variables can only be accessed from within static methods?
[/quote]

No, other way around.  Non-static variables can only be accessed from non-static methods.
March 20, 2005, 6:04 AM
Mr. Neo
Thank you for clarifying that.
March 20, 2005, 4:00 PM

Search