what is the function of 'this' operator ?

Answer Posted / 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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How to handle exception in c++, For example in a functions i am assigning memory to some variables and also in next instructions in am dividing one variable also. If this functions generates a error while allocating memory to those variable and also while dividing the variable if i divide by zero then catch block how it will identify that this error has cone from perticular instruction

1650


write a C++ program for booking using constructor and destructor.

2041


What is oops and its features?

580


what is different between oops and c++

1999


Where is pseudocode used?

563






Can you inherit a private class?

629


write a program to enter a string like"sunil is a good boy and seeking for a job" not more than 10 characters including space in one line,rest characters should b in other line.if the next line starts from in between the previous word,then print whole word to next line.

1789


why reinterpret cast is considered dangerous?

1896


• What are the desirable attributes for memory managment?

1723


What is new keyword in oops?

587


Write a program to sort the number with different sorts in one program ??

1912


What is constructor overloading in oop?

599


What is data binding in oops?

582


Can abstract class have normal methods?

606


What is encapsulation in oops?

534