Discussion :: OOPS Concepts - General Questions (Q.No.35)
Which of the following ways are legal to access a class data member using this pointer?
Answer: Option A
No answer description available for this question.
|Sai said: (Sep 2, 2012)|
|The most common reason for using the this keyword is because a field is shadowed by a method or constructor parameter.|
|Rahul Chaudhary said: (Oct 3, 2013)|
|What is the legal way to access class data member using this pointer in Java?|
|Vandana said: (Jan 11, 2014)|
|Why not this.x?|
|Ranjit said: (Jun 3, 2014)|
The This is a pointer which points to the current object (Through which the function or data member is being called. ).
To access any of the members of the class, we need a object or a pointer to the object.
So you can use This.x.
But when you are treating This as a pointer you should go with This->x.
|Ranjit said: (Jun 6, 2014)|
|But This.x is not allowed in C++ as This is a pointer to the Current object.
It is allowed in C#.
|Hruturaj Nikam said: (Oct 3, 2014)|
|(*this).x is equivalent to this->x.|
|Bhardbj said: (Jun 30, 2017)|
|You're right @Nikam.|
|Anoimee said: (Jan 12, 2019)|
|What is this pointer? Please explain me.|
|Garg said: (Jul 27, 2021)|
|This pointer contains the address of the object in which we are using this pointer.|
Post your comments here:
Email : (optional)
» Your comments will be displayed only after manual approval.