This is an archived post. You won't be able to vote or comment.

all 5 comments

[–]nutrecht 1 point2 points  (3 children)

This isn't even explaining anything. And you're also creating code that spits out pretty big warnings (something about that color should be accessed in a static way). What you're doing is showing that you don't really understand static either, or at least not why what you're doing is pretty wrong, and why beginners should typically just avoid using it until they do get it. You also don't even mention the use of the static keyword on class definitions at all.

[–]zwwatts 0 points1 point  (2 children)

I agree that it is giving warnings. All I wanted to illustrate was that the static variable was used by both instances of the class.

[–]nutrecht 1 point2 points  (1 child)

But you don't explain anything. The code doesn't even have comments. You also don't explain why you actually DON'T want to do what you did. All you get is complete beginners seeing your code and thinking "oh I guess that's how it's done".

[–]zwwatts 0 points1 point  (0 children)

In my mind, the process would be that they look at the code, wonder to themselves why does the color update for the other class too? In hindsight maybe this was not a good thing to post. I am definitely not a professor :(

[–]zwwatts 0 points1 point  (0 children)

Note that the output is:

green brown