I was looking through some English books and I found that in a dialogue one person ask another
"What are you?"
And answer was
I first time saw this way to ask about occupation. Can this question be used in this sense?
It seems a little rude to me, but then it is out of context.
The most common way to ask someone their profession is:
What do you do?
or the slightly longer
What do you do for a living?
Asking "what are you?" seems rude because in isolation it is not clear that you are asking about a person's profession. It could be misinterpreted as bringing into question someone's worth or validity.
But there could be contexts in which "what are you" would be just fine if certain other things have already been established in the conversation.
Person 1: My colleague in the police force has just been promoted to Chief Inspector.
Person 2: What are you?
Person 1: I'm a Chief Superintendent.
This doesn't seem as rude because it has already been established that the two people are talking about roles or job titles and the question is now drawing a comparison between two different roles.
Yes, albeit phrased like this it seems to be something a child might ask, and it is still quite vague and subject to misinterpretation.
A better way of asking might be (casual):
"What do you do for a living?"
Or (more formal):
"What's your occupation?"