Covariant Return Types

  • + 0 comments

    class Flower {

        String whatsYourName(){
        return "I have many names and types";
    }
    

    }

    class Jasmine extends Flower{ String whatsYourName(){ return "Jasmine"; } }

    class Lily extends Flower{ String whatsYourName(){ return "Lily"; } }

    class Region { public Flower yourNationalFlower(){ return new Flower(); } }

    class WestBengal extends Region{ public Jasmine yourNationalFlower(){ return new Jasmine(); } }

    class AndhraPradesh extends Region{ public Lily yourNationalFlower(){ return new Lily(); } }