Infosys interview question

To write snippets code of java based on the scenario