santhoshArun / Pass-by-value

java is a pure pass by value explanation

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Java is pass by value or likely passing reference as a value

First we need to understand there is a differnce between call by value and calling reference as a value.
C is call by value and Java is calling reference as a value.
Here we have used a swap function that swaps the value given to it and we are passing two things, one is a normal variable and the other instance of the class(reference type).
The normal variable remains unaffected and we don't need this here.
First we use setval() function that sets the value of the current instance with the help of reference, here it is using the reference and changing the value and not changing the reference variable itself.
So if we tried to change the reference variable like d = new demo(30); the variable remains unaffected.
Thus it is proved that we can't change the referece variable, we can use the reference or instance to alter the other values.
So java is call by value or calling reference as a value.

About

java is a pure pass by value explanation


Languages

Language:Java 100.0%