Strange behaviour when variable is re-declared in the extended class

In reply to abhi_inno:

This is Inheritance+Over-riding.

When you extend any class, the extended class inherits the parents members and methods. Because of which, when you create(new) an extended class, all the members/functions in Parent are also created along with the additional members/functions in the extended class.

So, in your example when child is created (new()), memory will be allocated to two color variables one for parent ‘color’ and one for child ‘color’. And when you try to access color from the respective handles the respective values are printed.