Skip to content

santhoshArun/Pass-by-value

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 

Repository files navigation

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

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages