G
Guest
public class Base
{
}
public class Derived : Base
{
}
public class Service
{
public void Send(Base baseObject)
{
// send baseObject
Console.Out.WriteLine("Called public void Send(Base baseObject)
signature");
}
public void Send(Subclass derivedObject)
{
// send derivedObject
Console.Out.WriteLine("Called public void Send(Subclass derivedObject)
signature");
}
}
public class MainClass
{
public static void Main(string[] args)
{
Base baseObject = new Base();
Derived derivedObject = new Derived();
Service service = new Service();
// this calls public void Send(Base baseObject) as expected
service.Send(baseObject);
// this calls public void Send(Base baseObject),
// but it should call public void Send(Subclass derivedObject),
// shouldn't it???
service.Send(derivedObject);
}
}
I expect this to work, but I tested it at runtime, verifying that the
instance is of the Derived class and it still calls the signature with the
base class.
thanks,
Dave Raskin
{
}
public class Derived : Base
{
}
public class Service
{
public void Send(Base baseObject)
{
// send baseObject
Console.Out.WriteLine("Called public void Send(Base baseObject)
signature");
}
public void Send(Subclass derivedObject)
{
// send derivedObject
Console.Out.WriteLine("Called public void Send(Subclass derivedObject)
signature");
}
}
public class MainClass
{
public static void Main(string[] args)
{
Base baseObject = new Base();
Derived derivedObject = new Derived();
Service service = new Service();
// this calls public void Send(Base baseObject) as expected
service.Send(baseObject);
// this calls public void Send(Base baseObject),
// but it should call public void Send(Subclass derivedObject),
// shouldn't it???
service.Send(derivedObject);
}
}
I expect this to work, but I tested it at runtime, verifying that the
instance is of the Derived class and it still calls the signature with the
base class.
thanks,
Dave Raskin