Unable to use instance variable in a static method

后端 未结 1 1297
我在风中等你
我在风中等你 2020-12-20 08:11

Why we cannot use instance variable in a static method? I know that static methods are called without creating instance of classes but what restric

相关标签:
1条回答
  • 2020-12-20 08:46

    Trying to put a non-static variable inside a static method makes the compiler wonder which instance of this variable should I really be updating? The static methods are not related to a class instance, so it will be impossible to call an instance variable on an instance when no instance exists.

    0 讨论(0)
提交回复
热议问题