The use of “this” in Java

后端 未结 13 1852
-上瘾入骨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

    You assign the parameter to itself in your example.

    More generally speaking: If you don't prepend a scope to your variable, the current scope is assumed - which is the function in your case. 'this.j' tells the jre to use the variable j within the object scope - the member variable of the object.

    0 讨论(0)
提交回复
热议问题