I will give an example from .NET.
ConcurrentDictionary<TKey, TValue> : IDictionary<TKey, TValue>, IDictionary
Here you can see ConcurrentDictionary implementing dictionary interfaces. However I can't access Add<TKey,TValue>
method from a ConcurrentDictionary instance. How is this possible?
IDictionary<int, int> dictionary = new ConcurrentDictionary<int, int>();
dictionary.Add(3, 3); //no errors
ConcurrentDictionary<int, int> concurrentDictionary = new ConcurrentDictionary<int, int>();
concurrentDictionary.Add(3, 3); //Cannot access private method here
Update:
I know how I can access it but I didn't know explicitly implementing an interface could allow changing access modifiers to internal. It still doesn't allow making it private though. Is this correct? A more detailed explanation about that part would be helpful. Also I would like to know some valid use cases please.