Covariant Return Types

Sort by

recency

|

105 Discussions

|

  • + 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(); } }

  • + 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(); } }

  • + 0 comments

    class Flower { String whatsYourName(){ return "I hava 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(); } }

  • + 0 comments

    import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader;

    //Complete the classes below abstract class Flower { public abstract String whatsYourName();

    }

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

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

    abstract class Region { public abstract Flower yourNationalFlower(); }

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

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

    public class Solution { public static void main(String[] args) throws IOException { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); String s = reader.readLine().trim(); Region region = null; switch (s) { case "WestBengal": region = new WestBengal(); break; case "AndhraPradesh": region = new AndhraPradesh(); break; } Flower flower = region.yourNationalFlower(); System.out.println(flower.whatsYourName()); } }

  • + 0 comments

    import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader;

    //Complete the classes below 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 { Flower yourNationalFlower(){ return new Flower(); } }

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

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

    public class Solution { public static void main(String[] args) throws IOException { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); String s = reader.readLine().trim(); Region region = null; switch (s) { case "WestBengal": region = new WestBengal(); break; case "AndhraPradesh": region = new AndhraPradesh(); break; } Flower flower = region.yourNationalFlower(); System.out.println(flower.whatsYourName()); } }