So if nftContract is treated as IERC721, then how does the trasnferFrom function even executes? Because the interface doesn't have any implementation written. Can you please help me with some more details.
Shouldn't it be declared as ERC721(nftContract) ??
the code executed is the code of whatever implements the interface
The I before ERC721 means interface. You can also do the same with a contract:
interface ISomeThing {} // interface
contract SomeThing is ISomeThing {} // contract that implements the interface
ISomeThing = ISomeThing(a); // using the interface (can only use functions defined in the interface)
SomeThing = SomeThing(a); // using the contract (can use all functions in the contract)