Can I Switch Universities After Accepting an Offer?

If I accept an offer from one university, but then receive an offer from my preferred university a week later, can I withdraw my acceptance from the first university and enroll in the second?

What kind of program is it? Undergraduate, graduate? When is the deadline to decide on the first offer? Do you have to reply to the first university before you hear from all other places you applied to?