In Java, what is an Impure Function? Please explain with example for 15 points.
Answers
Answered by
7
Impure functions,also called modifier functions, are those that can cause a changeof state in the object. That means, values of the object’s instance variables get modified or changed depending on the current state of the object on which the function operates. Such functions can cause some unwanted side effects if not carefully controlled by the access-modifier.
Neotros:
please would u give me an example as.well... u can edit it and add a pic of it
Answered by
6
Characteristics of impure function :
1. The return value of the impure functions does not solely depend on its arguments Hence, if you call the impure functions with the same set of arguments, you might get the deferent return values for example, math. random (), Date. now()
2. They may have any side effects like network or database calls
3. They may modify the arguments which are passed to them
1. The return value of the impure functions does not solely depend on its arguments Hence, if you call the impure functions with the same set of arguments, you might get the deferent return values for example, math. random (), Date. now()
2. They may have any side effects like network or database calls
3. They may modify the arguments which are passed to them
Similar questions