Ace school

with brainly

  • Get help from millions of students
  • Learn from experts with step-by-step explanations
  • Level-up by helping others

A community for students.

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
See more answers at brainly.com
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.

Join Brainly to access

this expert answer

SIGN UP FOR FREE
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.
Oh and this can be used to call class constructors of an object like this().
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"?

Not the answer you are looking for?

Search for more explanations.

Ask your own question

Other answers:

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 =/.
exactly; when you create a bunch of objects, each of them has their own variables.
Ok maybe I could understand better if I knew what would happened if the "this" keyword would not exist?
without the this keyword, an object can't refer to itself and its own fields in its methods
Hmmm I think I got it. Thank you so much @agdgdgdgwngo you're awesome!

Not the answer you are looking for?

Search for more explanations.

Ask your own question