Tech Mahindra interview question

Basics from OOPS