Why there is no local static variable in Java?

前端 未结 5 1874
星月不相逢
星月不相逢 2020-12-06 04:47

In C/C++ we use static local variables for maintaining a method\'s state. But why it is not supported in Java?

Yes, I can use an static field for this purpose. But i

5条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-06 05:13

    instance methods are invoked by the instance(objects) of the class . Static things belongs to the class not to the object that's why local variables are not static.Instance variables are static and they can also initialized at the time of class loading by static blocks. enter image description here

    for more information please visit :- https://www.youtube.com/watch?v=GGay1K5-Kcs&t=119s

提交回复
热议问题