You are viewing a single comment's thread. Return to all comments →
Maybe I missed the point, but I didn't see a reason to recreate the metho in each subclass.
class Flower { String myName = ""; public String whatsYourName() { return myName; } } class Jasmine extends Flower { public Jasmine() { myName = "Jasmine"; } } class Lily extends Flower { public Lily() { myName = "Lily"; } } class Region { Flower nationalFlower = null; public Flower yourNationalFlower() { return nationalFlower; } } class WestBengal extends Region { public WestBengal() { nationalFlower = new Jasmine(); } } class AndhraPradesh extends Region { public AndhraPradesh() { nationalFlower = new Lily(); } }
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 →
Maybe I missed the point, but I didn't see a reason to recreate the metho in each subclass.