You can but it's much better to be an expert in one field rather than a novice in multiple
Yes, you are right, it is always more logical to be an expert in a single field, but you know, some new things are coming out, for example, I think there is an artificial intelligence called Devinal and it can write code for itself. If you specialize in something and then that field is taken over by artificial intelligence, what is the point of not being an expert?