This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Another puzzling question

 
Arthur Blair
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Since with a static method, there is no "this" how do I refer to the static variable i1 defined at (1) without getting confused with the local variable i1 defined at (2)?
 
Praveen Ponna
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As you know the output of your program will be



because, in case of conflicting variable names the method m1 will prefers the local variable.

If you want to access the variable i1 defined at (1) then you have to provide the class name as the qualifier.

 
steven gerrard
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
one of the methods is as suggested by poonam
another method is to use new PassingAndCastingMoreArrays().i1=i2;
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic