Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Variable Scope.

807598Oct 12 2006 — edited Oct 12 2006
Hi,

Can anyone explain me why the following code gives comple time error ?
public class ScopeTest {
    private int i;
    
    public void testMethod() {
        int i=10;
        {
            int i = 12; //Compile time Error. Variable i already defined in the scope.
        }
    }
}
I am not able to understand clearly the scope rules ?

Thanks in advance,
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 9 2006
Added on Oct 12 2006
5 comments
213 views