Originally posted by saisnigdha samanchi:
Hi mamun;
s there is local to main s in try block is local to try something called shadowing concept works here(right?) so i think it shud be giving null as answer. If at all printing of "s" is in try block itself it shud be giving an ouput as "b". According to my understanding..
First of all please have a practice of pasting the actual-but-working code. In your code,
you have missed out the instantiation part "new Slave()" but its present in the next line when you explained. Also the import statement for FileNotFoundException is missing. I feel it would be a good practice, though it may not be really required as you may think.
Do you really wanted to have the shadowing effect? If so, please read about shadowing
here .
Shadowing does NOT work within the arguments of same method.
Option a: If at all you wanted to achieve this,
you should have to DEFINE the variable "s" inside the method but you are sure to get the "variable already defined" exception during compilation itself.
Option b: If you have declared the String variable "s" ONLY inside the try block, then you will get an exception in the System.out.println() statement as well with the message "cannot resolve symbol "s"."
Hope this helps!