sorry if this is a debated matter but from what i know, we can share accounts between consoles right?

lets say i have game X and my friend has game Y, if we switch our logins, can i play Y game under my ps username (get trophies in my account, etc?)