|
|
Re: java newbie hell
|
Posted: Feb 15, 2006 4:37 AM
|
|
It was not just wrong, it was completely wrong.
Try to immagine this:
The setColor method is supposed to set the color of the Sphere. Instead it did absolutely nothing. In fact, Sphere does not even have (= store the informations for) a color.
So your teacher made a mistake. Maybe it even was the scope that you find it?
setColor and getColor DO make sense.
1. public variables should be avoided. Instead get... and set... methods should be used.
2. If you want to do it right, don't use this syntax:
localColor = newColor;
but use localColor = new String(myColor);
The second line creates a COPY of the String contained in newColor, the first line only redirects myString to the current content of newString. This way, if someone modifies single characters of the String, localColor won't be affected. The getColor method should also return a COPY of myColor's content.
|
|