The use of “this” in Java

后端 未结 13 1931
-上瘾入骨i
-上瘾入骨i 2020-12-09 21:58

If I write the following class:

public class Example {

      int j;
      int k;

      public Example(int j, int k) {
           j = j;
           k = k;
          


        
13条回答
  •  粉色の甜心
    2020-12-09 23:00

    If you don't write this, then you assign the argument to itself; the argument variables shadow the instance variables.

提交回复
热议问题