what is the function of 'this' operator ?

Answers were Sorted based on User's Feedback



what is the function of 'this' operator ?..

Answer / sudha

"this" operator only access the current object.

Is This Answer Correct ?    41 Yes 4 No

what is the function of 'this' operator ?..

Answer / venkat

'this' is used to reffer current class variable

for example

class sample
{

int myvar=10;
void mymethod()
{
int myvar=20;
system.outprintln("The value of myvar is"+myvar)
system.outprintln("The value of myvar is"+this.myvar)
}
}


output :
20,10

Is This Answer Correct ?    39 Yes 15 No

what is the function of 'this' operator ?..

Answer / bhawna

Basically "this" opertaor is a part of instance variable
hiding,when a local variable has the same name as an
instance variable,the local variables hides the instance
variables

Is This Answer Correct ?    21 Yes 2 No

what is the function of 'this' operator ?..

Answer / walking legend

as we generally know a pointer is used to point to the
address of a particular variable and access its value.
Similarly,this is a pointer which always points to the
current object.

Is This Answer Correct ?    15 Yes 3 No

what is the function of 'this' operator ?..

Answer / madhu

'this' pointer is created when you create an object with
dynamic memory allocation. 'this' pointer will be created at
the time of object creation.
It holds the current object's address.
'this' cannot be used inside the static or a friend functions.

Is This Answer Correct ?    14 Yes 2 No

what is the function of 'this' operator ?..

Answer / sohaibx

it is an implicit pointer holding the address of current object.

Is This Answer Correct ?    5 Yes 0 No

what is the function of 'this' operator ?..

Answer / sourav

Hi Venkat,
In your coding example the concept of this pointer is
fine, but can u pls tell me the where the object is getting
formed ?

Is This Answer Correct ?    7 Yes 9 No

Post New Answer

More OOPS Interview Questions

why to use template classes in c++?

1 Answers  


What language is oop?

0 Answers  


#include <stdio.h> #include <alloc.h> #include <stdlib.h> #include <conio.h> void insert(struct btreenode **, int); void inorder(struct btreenode *); struct btreenode { struct btreenode *leftchild; struct btreenode *rightchild; int data; }; main() { struct btreenode *bt; bt=(struct btreenode *)NULL; int req,i=1,num; clrscr(); printf("Enter number of nodes"); scanf("%d",&req); while(i<=req) { printf("Enter element"); scanf("%d",&num); insert(&bt,num); i++; } inorder(bt); } void insert(struct btreenode **sr, int num) { if(*sr==NULL) { *sr=(struct btreenode *)malloc (sizeof(struct btreenode)); (*sr)->leftchild=(struct btreenode *)NULL; (*sr)->rightchild=(struct btreenode *)NULL; (*sr)->data=num; return; } else { if(num < (*sr)->data) insert(&(*sr)->leftchild,num); else insert(&(*sr)->rightchild,num); } return; } void inorder(struct btreenode *sr) { if(sr!=(struct btreenode *)NULL) { inorder(sr->leftchild); printf("\n %d",sr->data); inorder(sr->rightchild); } else return; } please Modify the given program and add two methods for post order and pre order traversals.

0 Answers  


What is the point of polymorphism?

0 Answers  


what uses of c++ language?

3 Answers  






What is this pointer in oop?

0 Answers  


When a private constructer is being inherited from one class to another class and when the object is instantiated is the space reserved for this private variable in the memory??

13 Answers   HCL, Honeywell,


Can we override main method?

0 Answers  


if u write a class do u write Assignment operator and copy constructor

1 Answers   Siemens,


difference between class and object

10 Answers   Chandan, IBM, Magic Soft,


How do you explain polymorphism?

0 Answers  


what is new modifier in C#

8 Answers   HCL,


Categories