This might be a bit too critical of the asker, but the question:
- has multiple issues (instead of just one)
- ... one of which is a typographical error.
- is probably a duplicate (of one or more of the posts I linked in a comment).
- isn't an MCVE (Minimal, Complete, and Verifiable example) (it is neither minimal nor complete, even after an edit was made to improve it).
- is a copy-paste of code from the internet - the asker doesn't really seem to understand what they're doing or why they're doing it (they added
Static
because that's what the code they copied did - the question would be more useful had they had a good reason for what they did, which they explained).
- is not a good example of the problem they're asking about (
static
is unnecessary here).
Even one of the above would mean the question (and thus also its answers) will be of limited use to future visitors.
So I'd suggest not focusing too much on this specific answer and instead focus on answers to questions that seem like they'd be more useful to others.
However, here are a few things I might recommend changing in your answer:
- Briefly explain what
static
means and why you'd use it, and include a link to a more detailed explanation.
- Possibly include why one might want to declare a
static
variable in a method, especially as opposed to in a class. This could help address the fact that the question is a bad example of the problem.
- Include a possible fix (or fixes). You already mentioned simply removing
static
, but this only works if static
is already unnecessary - it wouldn't work if the asker actually wanted it to be static
. You did include a link to some possible fixes, but it's better to also put those in the answer itself, at least briefly.
- I wouldn't have included the output, or I would've created my own MCVE, that possibly shows how static differs from non-static. This also goes back to the fact that the question isn't an MCVE - the output you posted is largely unrelated to the change you made, so it doesn't really show that your change works (not just that it runs), since the code does other things as well.
The first 2 points aren't strictly necessary to answer the question, but those few extra details can make the answer more useful to more people, and be the difference between a decent/good answer and a great answer. But figuring out exactly what to include, how to include it and how much detail to go into is a skill that takes time to master.