Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Static variables and scoping

 
John Lincoln
Ranch Hand
Posts: 192
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Can you same variable name for member variable and for variables in the method ? Is this because instance variables are on heap and local variables on stack ?

System.out.println(this.i); in the below code prints "10",which shows that static variable has been re-assigned.

How to tackle these type of questions


 
Keith Lynn
Ranch Hand
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes you can. This is called shadowing.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic