What's the meaning of static variables in an implementation of an interface?

后端 未结 4 1792
悲哀的现实
悲哀的现实 2020-12-04 09:37

I don\'t quite understand static variables when defined in the implementation of an interface. In methods I do understand how they differ from local variables, but not when

4条回答
  •  渐次进展
    2020-12-04 10:11

    "In both C and Objective-C, a static variable is a variable that is allocated for the entire lifetime of a program. This is in contrast to automatic variables, whose lifetime exists during a single function call; and dynamically-allocated variables like objects, which can be released from memory when no longer used. More simply put, a static variable's value is maintained throughout all function/method calls. When declared outside of a function, a static variable is visible to everything within the file in which it is declared; when declared inside a function or method, it is visible only within that function or method, but the value is retained between calls."

    Check out the complete explanation here:

    https://stackoverflow.com/a/4965145/951349

提交回复
热议问题