This week's book giveaway is in the General Computing forum. We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line! See this thread for details.
Which option most fully describes will happen when you attempt to compile and run the following code..
The output is given as option 4:..why cant be the output be option 2..since i has not initialized and used here..
public class MyAr{ public static void main(String argv[]) { MyAr m = new MyAr(); m.amethod(); } public void amethod(){ static int i; System.out.println(i); } }
1) Compilation and output of the value 0 2) Compile time error because i has not been initialized 3) Compilation and output of null 4) Compile time error
You are correct in that i has not been initialized. However, the more important issue is the use of the static keyword.
Inside of an instance method, a static modifier makes no sense at all. Static variables must be fields of the class. [ June 27, 2006: Message edited by: Peter MacMillan ]