You could build a contract that can interact with both your own token and someone else's token, but that doesn't have to do with your actual token contract.
A token contract just holds the basic data of the token itself and keeps tracks of who has some balance of it.
You ABC token contract has a
balances state variable that keeps track of addresses => amount of tokens.
The same is true for XYZ token.
If you wanted to have people send you XYZ tokens and exchange them for ABC tokens, you would have to build another contract that acts as an exchange for 2 tokens. Someone would send XYZ tokens to this exchange contract, it would calculate how many ABC tokens they should get in exchange and send that to them.