What is the 'this' (or 'self') reference conceptually, and how does an object know its own context?
Last updated
The this (or self) reference is an implicit pointer to the specific object on which a method was invoked, letting shared method code operate on that instance's own data.
Why it's needed: Method code exists once and is shared by all instances, so it needs a way to know "which object's fields am I acting on right now?"
How context is supplied:
When you call
obj.method(), the runtime passesobjas a hidden first argument; inside the method that becomesthis/self.In Python this is explicit (
def method(self)); in Java/C++/C# it's implicit but present.
What it enables: Disambiguating a field from a same-named parameter, passing the current object to other code, and method chaining by returning
this.Key insight: The object doesn't "know" itself magically: identity is threaded in per call. A static method has no
thisbecause it isn't bound to an instance.
- https://www.igmguru.com/blog/oops-interview-questions
- https://tryrehearsal.ai/technical-questions/explain-oops-concepts
- https://github.com/Devinterview-io/oop-interview-questions
- https://www.hirist.tech/blog/top-30-c-oops-interview-questions-and-answers/
- https://www.interviewbit.com/oops-interview-questions/
- https://blog.stackademic.com/dont-just-code-the-15-essential-practices-senior-developers-want-you-to-learn-now-84246fb2f6ed
- https://www.reddit.com/r/ExperiencedDevs/comments/1mpaewh/how_should_i_deal_with_junior_devs_that_debate/
- https://www.scaler.com/topics/oops-concepts-in-cpp/
- https://javatechonline.com/interview-questions-object-oriented-programming/
- https://henko.net/blog/my-favorite-interview-questions/
- https://utkrusht.ai/blog/python-interview-questions
- https://www.digitalocean.com/community/tutorials/oops-interview-questions-answers
- https://www.scribd.com/document/510810151/Fragile-base-class
- https://www.reddit.com/r/developersIndia/comments/1ktgmfk/software_development_interview_preparation/
- https://www.reddit.com/r/programming/comments/1m2ff3j/casey_muratori_the_big_oops_anatomy_of_a/
- https://www.reddit.com/r/SoftwareEngineering/comments/1ijqgpb/is_the_o_in_solid_still_relevant_or_just_a_relic/
- https://www.reddit.com/r/NorthropGrumman/comments/1bt1ug3/monthly_employmentcorporate_questions_and/