Click here to Skip to main content
15,902,017 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
why following is working?
public abstract class AbsClass
{
public void ShowData(){Console.WriteLine("some text");}
}

public interface IInterface
{
public void ShowData();
}
class otherclassName :AbsClass,IInterface
{
Static Void Main()
{
}
}

above class i have not implemented the interface ,but it is working without compile or Runtime error.

My dear c# techies, could you please explain. what i'm missing here.

What I have tried:

i have tried the same thing which has explained,but im not understand the basic.
please explain.
Posted
Updated 16-Jun-16 3:32am

Assuming you correct that so it compiles:
C#
public abstract class AbsClass
    {
    public void ShowData() { Console.WriteLine("some text"); }
    }
public interface IInterface
    {
    void ShowData();
    }
class otherclassName : AbsClass, IInterface
    {
    static void Main()
        {
        }
    }


It doesn't matter: there is an implementation of a method with the required signature in the class via the abstract class definition. That is enough for the interface to be happy.
If it's a problem, you can explicitly declare a method for the Interface:
C#
class otherclassName : AbsClass, IInterface
    {
    void IInterface.ShowData()
        {
        ...
        }
    ...
    }
And the system will sort it out for you based on the type of variable you call the class from.
 
Share this answer
 
Please see my past answers referenced in this one: Why we need to create instance for interface not for implementation?.

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900