Skip to main content

Call by value in JAVA

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

Popular posts from this blog

The old company comeup with new brand MAXBEN - Logo meaning

I am so happy to design this logo for my friend Suresh Mahalingam to boost his paint business to the next level. The first step in his process is logo design. He had a clear idea about his business, processes, pricing and target audience. I just collect all those information from him and created the logo with some appropriate meanings. Check out the logo here