File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Variable shadowing Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Variable shadowing" Watch "Variable shadowing" New topic
Author

Variable shadowing

Kaushal Shah
Greenhorn

Joined: Jul 20, 2004
Posts: 4
"A variable declared within the for-loop can not shadow a local variable of the enclosing method."

Could anyone give me an exaplanation and an example for this one?

Cheers,
Kosh!
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
Compiling:



results in two errors: a is already defined in aMethod() and b is already defined in aMethod().
It's explained in Section 14.4.2 of the JLS
[ July 30, 2004: Message edited by: Barry Gaunt ]

Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Variable shadowing