We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
importjava.io.*;importjava.util.*;publicclassSolution{publicstaticvoidmain(String[]args){/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */Stringin=newScanner(System.in).nextLine();try{Objecto=(Object)Class.forName(in).newInstance();if(oinstanceofAndhraPradesh){System.out.println(newAndhraPradesh().yourNationalFlower().whatsYourName());}elseif(oinstanceofWestBengal){System.out.println(newWestBengal().yourNationalFlower().whatsYourName());}}catch(Exceptionex){System.out.println("We got exception : "+ex);}}}classFlower{StringwhatsYourName(){return"I have many names and types";}}classJasmineextendsFlower{@OverrideStringwhatsYourName(){return"Jasmine";}}classLotusextendsFlower{@OverrideStringwhatsYourName(){return"Lotus";}}classLilyextendsFlower{@OverrideStringwhatsYourName(){return"Lily";}}classRegion{FloweryourNationalFlower(){returnnewFlower();}}classWestBengalextendsRegion{@OverrideFloweryourNationalFlower(){returnnewJasmine();}}classAndhraPradeshextendsRegion{@OverrideFloweryourNationalFlower(){returnnewLily();}}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Covariant Return Types
You are viewing a single comment's thread. Return to all comments →