Class scope variable vs method scope variable

后端 未结 3 370
独厮守ぢ
独厮守ぢ 2021-01-26 23:59

I know that variable scope is enclosed by a start of block { and an end of block }. If the same variable is declared within the block, then the compile

3条回答
  •  被撕碎了的回忆
    2021-01-27 00:13

    This is because int x=0 is not a variable but an instance field. Local variables are allowed to have the same names as fields. To distinguish between a variable and a field with the same name we use this prefix for instance fields or class name for class fields. E.g.

    int x = this.x
    

提交回复
热议问题