this java keyword

"this" is a keyword defined in the java programming language.

this java keyword

this java keyword

     

"this" is a keyword defined in the java programming language. Keywords are basically reserved words which have specific meaning relevant to a compiler in java programming language likewise the this keyword indicates the following :

-- The this keyword always refer to the current instance.
-- The this keyword helps in removing the ambiguity of references and allows to refer to the current instance within the running program.
--  key word this is used with variables as "this.variable" and specifies the number of member variable of this instance of that class.

In the example given below, the numbers of arguments in a constructor has the same name as a member variable of a class has.

Example to use the this keyword with a varaible:

public class Class2{

int number;
public Class2(int number){
this.number = number;
}
}