• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Another puzzling question

 
Arthur Blair
Ranch Hand
Posts: 71
  • 0
  • 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
  • 0
  • 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
  • 0
  • 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;
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic