Originally posted by Frankie Chee:
I understand what you mean that after '[', JVM is looking for another '[' because its thinking I am trying in declare int bok[], right?
Correct.
What does enclosing 'bok[0]=1' with curly braces mean to the JVM? I don't quite understand how executing it before any main method will eradicate the errors which occur previous. Could you explain just a bit more?
There was nothing wrong with the line, it's just that the compiler objected to where you put it. If you had put it inside a method or a constructor, then there would have been no compile errors. But putting it on a line by itself is disallowed.
Blocks of code surrounded by {} are executed when a class is first accessed, before any methods of that class are. How about giving bok[0] a random value?:
Originally posted by sever oon:
Carlos lost me on that last comment...I see no need for the braces.
Here are all the legal ways (I think I got 'em all, anyway) to declare an array
Nice example, I think I'll keep it.
I note that all of those ways where inside a method. What Frankie was attempting was outside of a method which is why I suggested the braces.