HackerRank Covariant Return Types in java problem solution

In this HackerRank Java Covariant Return Types problem solution, you will be given a partially completed code in the editor where the main method takes the name of a state (i.e., WestBengal, or AndhraPradesh) and prints the national flower of that state using the classes and methods written by you.

HackerRank Covariant Return Types in java problem solution

HackerRank Covariant Return Types in java problem solution

class State {
public Flower your_National_Flower() {
return new Flower();
}
}

class WestBengal extends State {

@Override
public Jasmin your_National_Flower() {
return new Jasmin();
}
}

class Karnataka extends State {

@Override
public Lotus your_National_Flower() {
return new Lotus();
}
}

class AndhraPradesh extends State {

@Override
public Lily your_National_Flower() {
return new Lily();
}
}

class Flower {
public String whats_Your_Name() {
return "I have many names and types";
}
}

class Jasmin extends Flower {

@Override
public String whats_Your_Name() {
return "Jasmine";
}
}

class Lotus extends Flower {
@Override
public String whats_Your_Name() {
return "Lotus";
}
}

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


Post a Comment

0 Comments