The difficulty with Music . This is clearly the desired output, but it doesn't seem to make sense that it would work that way. The compiler can't. To get a deeper understanding of the issue, it's useful to examine the subject of binding . You might not have heard the term before because it has never been an option with procedural languages.
C compilers have only one kind of method call, and that's early binding.
The confusing part of the above program revolves around early binding because the compiler cannot know the correct method to call when it has only an Instrument handle. The solution is called late binding , which means that the binding occurs at run-time based on the type of object. Late binding is also called dynamic binding or run-time binding . When a language implements late binding, there must be some mechanism to determine the type of the object at run-time and to call the appropriate method. That is, the compiler still doesn't know the object type, but the method-call mechanism finds out and calls the correct method body.