No, this is not my homework.
(Because next to me is a stack of answer sheets waiting to be marked.)
Q: If a local variable in a method has the same name as a variable in the main program, what will happen?
a) an error is generated
b) the variable in the main program is “hidden” until the method completes execution c) the variable in the main program will override the variable from the method d) None of the above.
And the answer of textbook b is pretty simple.
But on second thought, is it really “hidden”?
As far as I know, in pure object-oriented languages like C # and Java,
we can always use
this.x
or
MainProgram.x
.
, :
b #? ?
.