+ 1

What is the 'this' keyword?

3rd Mar 2017, 9:59 AM
Alok Agarwal
Alok Agarwal - avatar
3 Answers
+ 2
In java, this is a reference variable that refers to the current object.
3rd Mar 2017, 10:45 AM
rossi
rossi - avatar
+ 1
"this" refers to the current object For example: public class SomeClass { private int hehe = 321; public void printHehe() { System.out.printLn(this.hehe); // This would print 321 // "this refers to the current object - instance of SomeClass } } // of course you would need to call new SomeClass() and printHehe(), but this is just a demonstration
3rd Mar 2017, 10:47 AM
DefaltSimon
DefaltSimon - avatar
0
"This" is a implicit reference variable which holds the reference id of current object. It is also called implicit pointer in JAVA.We never use 'This' keyword into a static method or in a block.
24th Mar 2017, 6:49 AM
Priyanshi Saxena
Priyanshi Saxena - avatar