• Post Reply Bookmark Topic Watch Topic
  • New Topic

wich varible does it takes??  RSS feed

 
johny doe
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if i got the variable of this
int d;

and in the method as a paramemter it also recieves d

wich variable will it take if i wright the line

temp=d;

???
 
bart zagers
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The simplest way to find out is writing a small app. Assign different values to both variables, print out the temp variable and see which value gets printed.

Once you have tested it, you can read a bit on it (for example here).
 
Bill Shirley
Ranch Hand
Posts: 457
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Restated: I have an instance variable named foo, will it get masked by a parameter named foo?


The area of the code over which a variable's name may be validly used is called its scope.

Variables with more narrow scope will mask variables of wider scope.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!