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 ....
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 ....
nice work!!
ReplyDeleteThanku Praveen ;-)
DeleteI am a java coder from a long time, though never heard of shadowing, still uses same type of coding suggested :P
ReplyDeleteRajat ... I hope this post will enhance your coding skills ....:-)
ReplyDeleteThanx for this excellent post....Its really helpful....Great work....Keep it up :)
ReplyDeleteThanxxx aton Hardik ;-)
DeleteGOOD ONE...
ReplyDeleteThanku VERMA ;-)
ReplyDeleteGreat job :)
ReplyDeleteThanku kanishka
Delete