Drupal 8: Programmatically create a custom Block with sample code

In Drupal 8 by extending the Core class “BlockBase”. For each block we need to specify the ID and Display name for the block at annotation place. In BlockBase class there is function build(), we need to implement this function to render our content.