While studying C# from a book, I encountered some parts of the sample code that I couldn't comprehend. In C#, if a class inherits from an interface and implicitly implements the interface, the class's methods can be declared public. However, why can't the public access modifier be used when explicitly implementing the interface? Is there a clear reason?
namespace NotUnderstoodYet
{
interface IDog
{
void Eat();
}
interface ICat
{
void Eat();
}
class Pet : IDog, ICat
{
**public** void IDog.Eat() => WriteLine("Dog"); *<- Cannot comfile*
void ICat.Eat() => WriteLine("Cat");
}
class Print
{
static void Main(string[] args)
{
Pet pet = new Pet();
((IDog)pet).Eat();
}
}
}