[Solved] Program output what & why?


You are getting 0, 0 as output because of in the SetData method, variables i and j are local variables to the method. And because of this your class level variables i and j are not getting assigned.

public void SetData(int i, Single j)
    {
        i = i;
        j = j;
    }

change the above code to:

public void SetData(int i, Single j)
    {
        this.i = i; // using this will refer to the class level variables 
        this.j = j;
    }

Or you could name the local variables differently, then the local variables will not hide the class level variables.

public void SetData(int a, Single b)
    {
        i = a;
        j = b;
    }

Now the output will be 10 and 5.4

1

solved Program output what & why?