Quantcast

Got Homework?

Connect with other students for help. It's a free community.

  • across
    MIT Grad Student
    Online now
  • laura*
    Helped 1,000 students
    Online now
  • Hero
    College Math Guru
    Online now

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

No-data

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?

  • one year ago
  • one year ago

  • This Question is Closed
  1. agdgdgdgwngo
    Best Response
    You've already chosen the best response.
    Medals 1

    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.

    • one year ago
  2. agdgdgdgwngo
    Best Response
    You've already chosen the best response.
    Medals 1

    Oh and this can be used to call class constructors of an object like this().

    • one year ago
  3. No-data
    Best Response
    You've already chosen the best response.
    Medals 1

    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"?

    • one year ago
  4. No-data
    Best Response
    You've already chosen the best response.
    Medals 1

    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 =/.

    • one year ago
  5. agdgdgdgwngo
    Best Response
    You've already chosen the best response.
    Medals 1

    exactly; when you create a bunch of objects, each of them has their own variables.

    • one year ago
  6. No-data
    Best Response
    You've already chosen the best response.
    Medals 1

    Ok maybe I could understand better if I knew what would happened if the "this" keyword would not exist?

    • one year ago
  7. agdgdgdgwngo
    Best Response
    You've already chosen the best response.
    Medals 1

    without the this keyword, an object can't refer to itself and its own fields in its methods

    • one year ago
  8. No-data
    Best Response
    You've already chosen the best response.
    Medals 1

    Hmmm I think I got it. Thank you so much @agdgdgdgwngo you're awesome!

    • one year ago
    • Attachments:

See more questions >>>

Your question is ready. Sign up for free to start getting answers.

spraguer (Moderator)
5 → View Detailed Profile

is replying to Can someone tell me what button the professor is hitting...

23

  • Teamwork 19 Teammate
  • Problem Solving 19 Hero
  • You have blocked this person.
  • ✔ You're a fan Checking fan status...

Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.