i have class. have 2 instance member variables x , y, , class has function again takes 2 variables named x , y.
public class myclass { public int x; public int y; public int add(int x , int y) { return (x + y); } }
now creating instance of class , assigning values instance variables , if call function using same instance value of instance variables getting changed values passing parameter function shown below
myclass abs = new myclass(); abs.x = 10; abs.y = 11; console.writeline(abs.add(12, 13).tostring());
while debugging found value of instance variables changed 12 , 13 respectively. why so? happening.
i'm sure instance fields not changed. misinterpreted debugger output. if watch x
or y
while in add
method debugger (watch window) show values of method parameters. need watch this.x
or this.y
.
that's 1 of reasons why start instance fields underscore.
Comments
Post a Comment