The following code :

------------------
import std.stdio;
class A {
    void foo(A a) {
        writefln("A");
    }
}

class B : A {
    void foo(B b) {
        writefln("B");
    }
}

void main() {
    B b = new B;
    A a = b;
    assert(a is b);
    b.foo(b);
    a.foo(b);
}
--------------
outputs:
B
A


This is understandable as B.foo doesn't actually overrides A.foo. But somehow it's weird to get different outputs while "a" and "b" are basically the same object. Has anyone else encountered this problem in real life? Will C+++, java act the same way?

Reply via email to