0

What is the function of 'this' keyword in java and please make me understand a program with 'this' keyword through comments

20th Mar 2018, 9:10 AM
Devansh Gupta
Devansh Gupta - avatar
3 Answers
+ 1
Class Main(){ private int myInt =0; publicSetMyInt(int myInt){ this.myInt = myInt ;. // the first myInt is the one declared in the class and the second is the parameter passed in the setter method } } it's just one use case
20th Mar 2018, 10:26 AM
Farshaad Heydari
Farshaad Heydari - avatar
+ 1
tanks small very good
20th Mar 2018, 6:09 PM
â€ŽŰ§Ù…ÛŒŰ± Ű§ÛŒŰŹŰ§ŰŻÛŒâ€Ž
â€ŽŰ§Ù…ÛŒŰ± Ű§ÛŒŰŹŰ§ŰŻÛŒâ€Ž - avatar
0
this refers to the class that it is written inside it...... fo example when u have a private variable of type int , called. myInt. for the setter method (if the parameter has the same name . ) you would use. 'this.myInt' to refer to the variable that is a member of ur class (not the parameter in the setter method)
20th Mar 2018, 10:23 AM
Farshaad Heydari
Farshaad Heydari - avatar