I made a static method outside the main method And I made a static variable in the method, but there was an error... From what I learned, static is stored in the data area before the program is executed Why is there no static variable in the static method? I know it's meaningless, but I don't know why it doesn't work I really looked it up on Google for a few days, but I can't find an answer. Actually, I asked an intellectual, but he just said no, but he didn't tell me why, so I'm asking here ㅠ<
java
In Java, the static keyword can only be preceded by a member of the class. Because this is a rule, if you break this rule, an error will occur.
As you ask, adding static to a variable in the method is a rule violation because the variable is a local variable, not a member of the class. Therefore, errors occur and are not created. As mentioned above, the rule is that the static keyword can only be preceded by a member of the class.
You may be confused because the rules are different for each language.
© 2024 OneMinuteCode. All rights reserved.