That code will compile without errors, but it does not do what you think it does.
In class White, you are not initializing the member variable colorName that's in class Color. Instead, you have declared and initialized a new member variable colorName in class White. The member variable colorName from class Color isn't visible in class White, because it's private.
So with your code above, if you create a new White object and call getColor() on it, you will get back null instead of a string containing "White" - because the variable colorName in class Color is null.
If you want to set colorName in class Color to "White", there are several things you could do:
1. Call setColor(...) in the constructor of class White. 2. Make colorName in class Color protected instead of private, and initialize it in the constuctor of class White (you'll have to remove the member variable colorName from class White).