You are confusing the implementation of an interface with the extension of concrete class. I believe this is causing you to think of the relationship backwards. An interface, by definition, has no concrete implementation. It only defines a contract that implementing classes must use. Perhaps an example can help clarify.
Suppose we have an interface called IBank
. This interface has the following definition:
IBank
{
void AddMoney(int amount);
void RemoveMoney(int amount);
int GetBalance();
}
Then we have a concrete implementation of this interface as follows:
EuroBank : IBank
{
void AddMoney(int amount){ balance+= amount; }
void RemoveMoney(int amount){ balance-= amount; }
int GetBalance(){ return balance; }
private int balance;
}
I cannot create a new instance of IBank
. The following code will not compile.
IBank bank = new IBank;
Instead, I must create a new concrete instance of a bank that I can treat as an IBank
. I can then call methods on this class.
IBank bank = new EuroBank;
bank.AddMoney(7);
So when I call AddMoney
, I using the method defined by the interface, but I am actually calling the concrete implementation of AddMoney
on the EuroBank
class.
So in your example, you are calling the m11
method on the ab
class. However, ab
implements both i11
and i22
. Therefore, it can be treated as both an i11
and i22
object. Both of the following lines of code will work.
i11 first = new ab();
i22 second = new ab();
I can call the m11
method on either object, but it will always use the concrete implementation of the method found on the object ab
.