This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
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

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Variable shadowing" Watch "Variable shadowing" New topic

Variable shadowing

Kaushal Shah

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?

Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729

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:
subject: Variable shadowing
It's not a secret anymore!