Dumb question???

Can you orgasm when you masturbate or only when you have sex??? And how to you have an orgasm?

Thanks