How to display selected category names of custom post type in wordpress

Here is code snippet to display selected category names of custom post type in wordpress.

To get the categories of a custom post type you have call get_the_terms() and setup the registered category name like this

<?php
$terms = get_the_terms( $post->ID , 'myposttype_category' );
foreach ( $terms as $term ) {
  echo $term->name;
}
?>