Computer Science, asked by Neotros, 1 year ago

In Java, what is an Impure Function? Please explain with example for 15 points.

Answers

Answered by kartik179
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
Neotros: i mean of the exmaple
Neotros: example
Anonymous: Like set age()
Anonymous: setAge()
Neotros: thanks
Neotros: but i need a broader example
Answered by RDimpy111
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

Neotros: thanks
Neotros: I didn't ask for characteristics of impure function though
RDimpy111: u most welcome
Similar questions