anonymous
  • anonymous
Hi, I'm having troubles understanding the "this" keyword in Java. I already googled it and red the Java tutorial on that plus some other webpages. It says: "The most common reason for using the "this" keyword is because a field is shadowed by a method or constructor parameter". I don't quite get the meaning of "is shadowed by ...". Could someone help me please?
Computer Science
  • Stacey Warren - Expert brainly.com
Hey! We 've verified this expert answer for you, click below to unlock the details :)
SOLVED
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.
jamiebookeater
  • jamiebookeater
I got my questions answered at brainly.com in under 10 minutes. Go to brainly.com now for free help!
anonymous
  • anonymous
The `this' keyword is basically an alias for the current object that invoked the method. When you are writing some class methods and you need to mutate variables that are local to an instance of that class, you may use `this' to refer to that particular instance/object.
anonymous
  • anonymous
Oh and this can be used to call class constructors of an object like this().
anonymous
  • anonymous
I understood the last thing and it's pretty cool. What do you mean by "mutate variables that are local to an instance of that class"?

Looking for something else?

Not the answer you are looking for? Search for more explanations.

More answers

anonymous
  • anonymous
I know that a local variable is a variable that is inside a method and that an instance variable is outside any method. But I think that is not enough for me to understand =/.
anonymous
  • anonymous
exactly; when you create a bunch of objects, each of them has their own variables.
anonymous
  • anonymous
Ok maybe I could understand better if I knew what would happened if the "this" keyword would not exist?
anonymous
  • anonymous
without the this keyword, an object can't refer to itself and its own fields in its methods
anonymous
  • anonymous
Hmmm I think I got it. Thank you so much @agdgdgdgwngo you're awesome!

Looking for something else?

Not the answer you are looking for? Search for more explanations.