0
What is the function of 'this' keyword in java and please make me understand a program with 'this' keyword through comments
3 ответов
+ 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
+ 1
tanks small very good
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)