Can someone please help me understand why this code snippet returns \"Bar-Bar-Quux\"? I\'m having a hard time understanding this even after reading up on interfaces.
Interfaces by definition have no associated implementation, which is to say their methods are always virtual and abstract. In contrast, the class Bar above defines a concrete implementation for GetName. This satisfies the contract required to implement IFoo.
Class Baz now inherits from Bar and declares a new method GetName. That is to say that the parent class Bar has a method with the same name, but it is completely ignored when working with Baz objects explicitly.
However, if a Baz object is cast as a Bar, or simply assigned to a variable of type Bar or IFoo, it will do as it's told and behave like a Bar. In other words, the method name GetName refers to Bar.GetName instead of Baz.GetName.
Now, in the third case, Quux both inherits from Bar and implements IFoo. Now, when cast as an IFoo it will provide its own implementation (according to the specification provided in Mike Z's answer).
When a Quux is cast as a Bar, however, it returns "Bar", just as Baz does.