QUESTIONS TO ANSWER:
In your own words what is the difference between pass by reference and pass by value?
What is a privacy leak in Java?
Why could it be important to prevent privacy leaks, besides just the obvious answer of unintentionally sharing data?
Difference between pass by reference and pass by value :
When a function is called, the arguments in a function can be passed by value or passed by reference. Pass by value means that a copy of the actual parameter’s value is made in memory, i.e. the caller and callee have two independent variables with the same value. If the callee modifies the parameter value, the effect is not visible to the caller.
Pass by reference (also called pass by address) means to pass the reference of an argument in the calling function to the corresponding formal parameter of the called function so that a copy of the address of the actual parameter is made in memory, i.e. the caller and the callee use the same variable for the parameter. If the callee modifies the parameter variable, the effect is visible to the caller’s variable.
privacy leak :
When a class has class type instance variables and returns a reference to them allowing an outside user to modify them.
How to prevent privacy leak:
Make all instance variables primitive types
Only return clones of any object that you return
Only use instance variables that have no mutator methods
Please do give a like thanks...!!
Get Answers For Free
Most questions answered within 1 hours.