HI WELCOME TO KANSIRIS

Local variable and Global variable with same name and how it works?

Leave a Comment

Since the local variables are preferred over the class variables, the class variables are never set. Inside the getdata method you are setting the local (method scoped) variables to their own value. Hence, in the displaydata method, you are printing the default values of the integers (0).
To fix this, you can either change the names of the variables, by prefixing them for example, or use this to set the scope.
public void getdata(int i,Single j)
{
    this.i = i;
    this.j = j;
}

0 comments:

Post a Comment

Note: only a member of this blog may post a comment.