It doesnt make any different, its the same thing.
> It doesnt make any different, its the same thing.
>
[quoted text clipped - 19 lines]
> > You should have in above line
> > private Side[] Sides =new Side[4];
It goes further than that... What he's describing is stylistic in
nature, but the convention is that it's better to specify it as the
respondent described because it clearly shows that the variable "Sides"
is "an array of Side objects". In addition, by convention, variables
should always begin with lower case letters and class names with upper
case, so that "sides" should be the proper name.
But the actual problem the compiler is reporting (since it doesn't
enforce coding conventions, only language requirements) is that you have
initialization code (as in "Sides[0] = new Side();") outside of any
method, which is not legal.
Two solutions come to mind, since you say you want the array created and
filled when a new Square is created. One is to do the initialization in
the constructor. The second would be to create the array with the
initializations, like this:
private Side[] sides =
new Side[] {new Side(), new Side(), new Side(), new Side()};
This is often not an option for arrays, but a small one like this can
use it. It might still be better, depending on what else goes on in
your code, to do it in a constructor.
= Steve =

Signature
Steve W. Jackson
Montgomery, Alabama
Colin Hemmings - 13 Jan 2006 18:39 GMT
Ok, thank you Steve thats great, I went with a constructor in the end.
As for my declaration of the array are you saying its better the way I
have declared it or is the stylistic way better?
Thanks again
>>It doesnt make any different, its the same thing.
>>
[quoted text clipped - 45 lines]
>
> = Steve =
Steve W. Jackson - 13 Jan 2006 20:31 GMT
> Ok, thank you Steve thats great, I went with a constructor in the end.
> As for my declaration of the array are you saying its better the way I
> have declared it or is the stylistic way better?
>
> Thanks again
[ snip ]
Here we go with that top-posting thing again...
> >>>You should have in above line
> >>>private Side[] Sides =new Side[4];
This snippet from the other poster's reply indicates what I'm
describing, which is that it's considered best if you declare your
variable "Sides" to be of type "Side[]" -- or "array of Side". The
code included in your original post said "Side Sides[]" which is
syntactically valid (barring the other issues already addressed), just
not recommended style. Sun's Java coding conventions are at
<http://java.sun.com/docs/codeconv/html/CodeConvTOC.doc.html>. This is
a great resource for coding style.
= Steve =

Signature
Steve W. Jackson
Montgomery, Alabama