0
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#>

2
Contributors
1
Reply
2
Views
8 Years
Discussion Span
Last Post by LizR
0

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!

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.