25-08-2017, 09:32 PM
PARAMETRS PASSING IN JAVA
IT@GEP Prudvi.ppt (Size: 694.5 KB / Downloads: 33)
Parameter Passing – Primitive Type
The first way is call-by-value.
Java passes all parameters to a method by value.
The actual parameters (the values that are passed in) are assigned to the formal parameters (declared in the method header).
This means that the value of the actual parameter is copied into the formal parameter.
Therefore, changes made to the parameter of the subroutine have no effect on the argument.
Parameter Passing – Reference Type
The second way an argument can be passed is call-by-reference.
When an object is passed to a method, Java passes a reference to that object.
The value that is copied is the address of the actual object.
Therefore it is important to understand that when a formal parameter object is used it modifies the actual object state permanently.
When a simple type is passed to a method, it is done by use of call-by-value. Objects are passed by use of call-by-reference