At least in the USA, yes. The US education system allows the individual student a great deal of freedom in the choice of field(s) of study. You can do your undergraduate degree in one subject and your graduate degree in another.
Of ocurse, to get into graduate school in a particular subject, you have to have sufficient background. Thus it is relatively uncommon for someone to get, say, a degree in history but decide to go to graduate school in physics instead. It is possible, however. In some cases people pursue jobs in one area and gradually develop an interest in another topic, perhaps gaining research experience in the private sector or taking classes informally in order to get the background they need for grad school.
Also, getting an undergraduate degree in a particular subject in the US does not mean you only study that subject. You can take a wide variety of classes outside your nominal area of focus, and in some cases thereby get enough experience to apply to grad school in an another subject. Also, you can "double major", completing more than one official course of study. Thus someone may study multiple subjects in undergrad, and decide on one to continue in grad school.
Switching fields between undergrad and grad is not that uncommon, especially if the fields are closely related (e.g., math BS followed by physics PhD). I've personally known quite a few people who have switched fields from undergrad to grad, sometimes with a long detour outside of school. For instance, one fellow I know got undergrad degrees in political science and Asian studies, spent more than a decade as a corporate executive, and eventually went back to get a PhD in linguistics.