Difference between Static methods and Instance methods

前端 未结 10 1309
青春惊慌失措
青春惊慌失措 2020-11-22 05:30

I was just reading over the text given to me in my textbook and I\'m not really sure I understand what it is saying. It\'s basically telling me that static methods or class

10条回答
  •  遇见更好的自我
    2020-11-22 05:57

    If state of a method is not supposed to be changed or its not going to use any instance variables.

    You want to call method without instance.

    If it only works on arguments provided to it.

    Utility functions are good instance of static methods. i.e math.pow(), this function is not going to change the state for different values. So it is static.

提交回复
热议问题