if yes then how it can refer to a ActionCharacter fight() method?
Utkarsh- Note this interesting fact - An inherited method CAN implement an interface on behalf of the subclass !!
ActionCharacter's fight() is public and hence is inherited by Hero class. And this inherited fight() method implements the CanFight interface on behalf of Hero.
And this is despite the fact that the ActionCharacter class where fight() is originally defined does not 'implement' CanFight interface !! And despite the fact that Hero itself is defined to 'implement' the interface but does not itself define the method of the interface !!
It is because the inherited fight() method is implementing the CanFight interface on behalf of Hero, that Hero class is not abstract, although the Hero class itself does not define the method fight() of CanFight interface.
Thus a variable of type CanFight can hold a reference to an object of type Hero (An interface type variable can hold reference to object of a class implementing that interface type).
[This message has been edited by Rahul Rathore (edited March 13, 2001).]