Two syntax questions about arrays and classes

An easy way to think about this: Anything that is defined in curly brackets, stays in the curly brackets.

So, if you have a pair of { and } brackets, anything that is defined inside of them, regardless of what these brackets mean, can only be accessed from within these brackets, and is essentially lost and then eventually garbage-collected by Java when it gets to that }.

Obviously this doesn’t apply if you modify something that was made before curly brackets, which is why answer to the first question by @GoToLoop works.
I mean, it probably doesn’t, but it’s helpful and easier to think about it that way.

Also, you can define your array as:

Class[] array = {new Class(0,0), new Class(0,50), new Class(0,100) }; //...

And, uh, in that case, brackets count as you are modifying that array you created outside of them, not defining new things.

2 Likes