Saturday, 27 June 2015

THE FOLLOWING BLOG DISCUSSES ONE OF THE MOST CONFUSING TOPIC OF JAVA ... i.e. 
                 JAVA SHADOWING
I'M SURE THIS POST WILL BE A BOON FOR JAVA PROGRAMMERS ........ 


Hiding a variable is  called shadowing. A variable can be shadowed if another variable  exists in its scope. So what is a scope?

Scope =>

Scope is a region of program within which a variable can be accessed. Each type of variable have their own scope. So if there are two variables with same name in the same scope then they will be shadowed. There are different scenarios in which variables are shadowed.

CONSIDER THE FOLLOWING EXAMPLE .....

In this example .....x = 0 is overshadowed by x = 1 which is further overshadowed by x = 23.We can access them by casting instance variable to the super class variable .



             
 In the above program comment the JAVA lines 8 & 9 and this will help you to access the variable of the class ShadowTest also .


I HOPE THIS POST WILL  HELP THE CODERS TO UNDERSTAND THE SIMPLE CONCEPT OF JAVA SHADOWING ....

10 comments: