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.BufferedReader;importjava.io.IOException;importjava.io.InputStreamReader;//Complete the classes belowclassFlower{publicStringwhatsYourName(){return"I have many names and types";}}classJasmineextendsFlower{@OverridepublicStringwhatsYourName(){return"Jasmine";}}classLilyextendsFlower{@OverridepublicStringwhatsYourName(){return"Lily";}}classRegion{publicFloweryourNationalFlower(){returnnewFlower();}}classWestBengalextendsRegion{@OverridepublicFloweryourNationalFlower(){returnnewJasmine();}}classAndhraPradeshextendsRegion{@OverridepublicFloweryourNationalFlower(){returnnewLily();}}publicclassSolution{publicstaticvoidmain(String[]args)throwsIOException{BufferedReaderreader=newBufferedReader(newInputStreamReader(System.in));Strings=reader.readLine().trim();Regionregion=switch(s){case"WestBengal"->newWestBengal();case"AndhraPradesh"->newAndhraPradesh();default->newRegion();};Flowerflower=region.yourNationalFlower();System.out.println(flower.whatsYourName());}}
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 →