polymorphism: overloading vs. overriding
Mike Parker
aldacron71 at yahoo.com
Sun May 7 08:26:07 PDT 2006
Bruno Medeiros wrote:
> Mike Parker wrote:
>>
>> This line is the key:
>>
>> Foo foo = new Bar();
>>
>> foo is an instance of Foo, not an instance of Bar,
>
> No, that is wrong, foo *is* an instance of Bar. (yet, it's type contract
> is only that it is a Foo)
>
Yes, yes. Underneath the foo is an instance of Bar. But because, as you
say, the type contract is that of Foo then you are effectively dealing
with a Foo and not a Bar. It should only be treated as a Bar when you
downcast.
More information about the Digitalmars-d
mailing list