Java only allowing global variables to be static?

后端 未结 5 506
难免孤独
难免孤独 2021-01-19 01:40

So I just started coding a Java program I\'m writing and it\'s telling me that my global variables need to be static. I don\'t understand why it\'s telling me this because I

5条回答
  •  花落未央
    2021-01-19 02:29

    if you are using some property in a static method then the property should be static. I am guessing you are using these global variables within the main method thus java is throwing this error. If you want to still access a global variable then probably define a class that is initialized with these global variables and instantiate the same in your main function and u can use it.

提交回复
热议问题