using System;

/// <summary>
/// Summary description for Class1
/// </summary>

interface I
{
    void dis();
}
class B:I
{
    public virtual void dis()
    {
        Console.WriteLine("dis() in Base");
    }
}
class D : B
{
    public override void dis()
    {
        Console.WriteLine("dis() in Derived");
    }
}
class c2
{
    public static void Main()
    {
        D d = new D();
        d.dis();
        I i = (I)d;// calls Base version even though D hv a fun of the correct form.Bcoz D doesn't implement interface.
        i.dis();
    }

}

output:

C:\workcode\C#>c2.exe
dis() in Derived
dis() in Derived

C:\workcode\C#>

It should give o/p:


C:\workcode\C#>c2.exe
dis() in Derived
dis() in Base

C:\workcode\C#>

I dsiagree, I would expect what you gave it, because you've overriden it, and it still conforms to the interface, but the class itself is still there!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.