What is the meaning of “this” in Java?

后端 未结 21 2574
走了就别回头了
走了就别回头了 2020-11-21 05:41

Normally, I use this in constructors only.

I understand that it is used to identify the parameter variable (by using this.something), if i

21条回答
  •  迷失自我
    2020-11-21 06:03

    If the instance variables are same as the variables that are declared in the constructor then we use "this" to assign data.

    class Example{
         int assign;// instance variable
    
         Example(int assign){ // variable inside constructor
              this.assign=assign;
         }
    }
    

    Hope this helps.

提交回复
热议问题