Monday, May 24, 2010

Can you allow allow methods with-in a java class to access a input stream?

I'm writing a java program and I've defined an input stream (using the Scanner class) before any methods are listed. All the methods except main seem to be able to use it, but hey are defined like:


public void name()





my main method looks like:


public static void main(String[] args)





as per usual. When I compile the program, I get errors saying that a non-static variable cannot be referenced from a static context. However, when I take "static" out of the main mehtod declaration, I get a weird runtime error. Does anyone know what's goin on here? I'm used to C++ where we have to deal with much less of this silliness.

Can you allow allow methods with-in a java class to access a input stream?
Yes, it is allowed.


No comments:

Post a Comment