Thursday, December 2, 2010

what are shadow variables in java

A shadowed variable is a variable that would otherwise be accessible, but is
temporarily made unavailable because a variable with the same name has
been declared in a more immediate scope.
Example:

public class ShadowApp
{
static int x;
public static void main(String[] args)
{
x = 5;
System.out.println(“x = “ + x);
int x;
x = 10;
System.out.println(“x = “ + x);
System.out.println(“ShadowApp.x = “ +
ShadowApp.x);
}
}

No comments:

Post a Comment