public class Test
{
public void callByValue(int x)
{
x=100;
}
public static void main(String[] args)
{
int x=50;
Test t = new Test();
t.callByValue(x);
System.out.println(x);
}
}
Output is: 50
In the above example, even though the value of X is 100, we are setting local variable as 50 and then calling the "callByValue()" method. So, it will reset the value of x from 100 to 50.
Thus the output is: 50
For more reference: http://www.studytonight.com/java/method-and-overloaded-method.php
{
public void callByValue(int x)
{
x=100;
}
public static void main(String[] args)
{
int x=50;
Test t = new Test();
t.callByValue(x);
System.out.println(x);
}
}
Output is: 50
In the above example, even though the value of X is 100, we are setting local variable as 50 and then calling the "callByValue()" method. So, it will reset the value of x from 100 to 50.
Thus the output is: 50
For more reference: http://www.studytonight.com/java/method-and-overloaded-method.php