the simple answer to your question is this
get_the_category();
Using your example you can say
if (in_category( array('X', 'Y', 'Z') )) {
echo get_the_category();
}
This tag may be used outside The Loop by passing a post ID as the parameter.
For more information and usage of get_the_category()
visit the next link
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…