java 选择一个类,返回该实例对象
2017-03-24 23:12 backyyan 阅读(1480) 评论(0) 编辑 收藏 举报class Flower { String whatsYourName() { return "I have many names and types."; } } class Jasmine extends Flower { @Override String whatsYourName() { return "Jasmine"; } } class Lily extends Flower { @Override String whatsYourName() { return "Lily"; } } class Lotus extends Flower { @Override String whatsYourName() { return "Lotus"; } } class State { Flower yourNationalFlower() { return new Flower(); } } class WestBengal extends State { @Override Jasmine yourNationalFlower() { return new Jasmine(); } } class Karnataka extends State { @Override Lotus yourNationalFlower() { return new Lotus(); } } class AndhraPradesh extends State { @Override Lily yourNationalFlower() { return new Lily(); } }