HCLTech interview question

Was asked to code an overiding example.