I have some doubt to implementation of class and interface
I have 2 class like this
Public Class A:IFinal
{
private string name=string.Empty;
A()
{
name = "Pankaj";
}
public string MyName()
{
return name;
}
public string YourName()
{
return "Amit";
}
}
Public Class B:IFinal
{
private string name=string.Empty;
B()
{
name = "Amit";
}
public string GetNane()
{
return name;
}
public string YourName()
{
return "Joy";
}
}
Question:
-
Now i have a interface IFinal and i want to implement this interface in class A & B for method YourName() like this
public interface IFinal
{string YourName();// Class A & Class B }
Is it possible to implement on this way? if yes then How can i declare YourName() in interface and how can i use this?
- Is it possible to declare virtual method in interface?like in class A & B we have a virtual method which need to be declare in interface.
You can make the method virtual in your implementation eg:
Or you could use a common base implementation which both A and B derive from, eg