You can achieve like this also:
<?php
namespace Mastering\Itdesire\Block\Index;
class Index extends \Magento\Framework\View\Element\Template
{
protected $_customer;
public function __construct(
\Magento\Customer\Model\Customer $customer,
\Magento\Backend\Block\Template\Context $context
)
{
$this->_customer = $customer;
parent::__construct($context);
}
public function getCustomer()
{
$customerId = '189'; //You customer ID
$customer = $this->_customer->getCollection()->addAttributeToFilter('entity_id', array('eq' => $customerId));
echo "Customer Firstname:".$customer->getFirstname();
echo "Customer Lastname:".$customer->getLastname();
}
}
Hope, This will help you some extend.