☞There are two types of functions in Java.
1. Pure Functions 2. Impure Functions
☞A function which returns a value to its caller module, is called a pure function.
☞It is also called accesser method, as it does not change the states of an object.
class Addition{ int sum(int a, int b){ int c=a+b; return c; //returning a value to a calling function } public static void main(String args[]){ Addition obj=new Addition(); int result=obj.sum(5,6); //calling a function System.out.println(result); } }
11
☞A function which may not return a value to its caller module, is called impure function.
☞It basically changes the state of an object during function call.
class Addition{
void sum(int a, int b){
System.out.println(a+b);
}
public static void main(String args[]){
Addition obj=new Addition();
obj.sum(5,6); //function calling
}
}
11