I am trying to understand why it behaves as below
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AbstarctWithInterfcae
{
public interface IBase
{
void Display();
}
public abstract class Base : IBase
{
public void Display()
{
Console.WriteLine("Base Display");
}
}
public class child1 : Base, IBase
{
public new void Display()
{
Console.WriteLine("child1 Display");
}
}
public class child2 : Base,IBase
{
public new void Display()
{
Console.WriteLine("child2 Display");
}
}
class Program
{
static void Main(string[] args)
{
IBase obj = new child1();
obj.Display(); // writing child1 display
IBase obj2 = new child2();
obj.Display(); //Wrirting child1 dispaly
Console.ReadLine();
}
}
}
First Question :
In the above program as i am using new it should call base class method why it is calling Child 1 Display?
As per my understanding we have base class which already implemented the IBase so when we create instance for the child1 by referring to the interface it should call the base class method as it is inhering the base class and having the new key word.
If anybody gives explanation that would be appreciated