Hi Lucky314159,
Look variable x is instance variable, but the variable x inside function
setOrigin is local variable.
So it can't be the same value.
You can use "This" keywords to assingn value of x inside the function.
E.g.
public class Circle {
private int x, y, radius;
x=5;
public void setOrigin(int x, int y) {
this.x=x;
this.y=y;
}
}
Initially the value of x is 5, but after calling the method setOrigin,
the value of x will depends upon
The parameter of function.
I hope u might be understand the logic.
Thanks,
Karunjay
-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of
redtigerrun
Sent: Friday, June 26, 2009 6:27 AM
To: Free Java Programming Online Training Course By Sang Shin
Subject: [java programming] Shadowing Fields
Dear JAVA Gods:
I am reading the material on shadowing. Here is the code.
public class Circle {
private int x, y, radius;
public void setOrigin(int x, int y) {
...
}
}
I my understanding there is a field which is also used as the parameter.
So for instance, if private int x = 5 then the parameter x of setOrigin
will also equal 5. What do you think?
--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/javaprogrammingwithpassion?hl=en
-~----------~----~----~----~------~----~------~--~---