Infosys interview question

Related to oops and simple coding question