Consider the following classes:
public class X {};
public class Y : X {};
public class Z : X {};
public class A {
public bool foo (X bar) {
return false;
}
};
public class B : A {
public bool foo (Y bar) {
return true;
}
};
public class C : A {
public bool foo (Z bar) {
return true;
}
};
Is there a way to achieve the following desired output?
A obj1 = new B();
A obj2 = new C();
obj1.foo(new Y()); // This should run class B's implementation and return true
obj1.foo(new Z()); // This should default to class A's implementation and return false
obj2.foo(new Y()); // This should default to class A's implementation and return false
obj2.foo(new Z()); // This should run class C's implementation and return true
The issue I am having is that class A's implementation is always being called regardless of the arguments passed.