如何同层次类转换? Parrot向Swallow?不可能,肯定会提示classcastexception 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 Adapter的基本思想是:public class SwallowParrot extends Swallow { private Parrot parrot; public void eat () { super.eat(); parrot.eat(); }}但是,你用公共接口用定义这些会更方便:public interface BirdIF { void fly(); void eat();}public interface SwallowIF extends BirdIF { void swim();}public interface ParrotIF extends BirdIF { void jump();}public class ParrotAndSwallow implments BirdIF, SwallowIF, ParrotIF {}test() { ParrotAndSwallow hybrid = new ParrotAndSwallow(); BirdIF asBird = (BirdIF) hybrid; ParrotIF asParrot = (ParrotIF) hybrid; SwallowIF asSwallow = (SwallowIF) hybrid;} ssh框架,包升级后出错、。 ubuntu 下面部署web项目乱码问题!! 有关action的namespace的问题 创业,有些问题要请教,散分。。 高手進:Hibernate問題; Tomcat安装问题 无法执行JSP文件了,请教啊 "OnLineTestCase.java": package junit.framework does not exist at line 10, column 53 急-----java word操作! 我的怎么不行?有j2ee这个应用程序? 为什么j2eesdk-1.4里面没有j2ee.bat文件啊 struts+hibernate 查询
private Parrot parrot;
public void eat () {
super.eat();
parrot.eat();
}
}但是,你用公共接口用定义这些会更方便:
public interface BirdIF {
void fly();
void eat();
}public interface SwallowIF extends BirdIF {
void swim();
}public interface ParrotIF extends BirdIF {
void jump();
}public class ParrotAndSwallow implments BirdIF, SwallowIF, ParrotIF {}test() {
ParrotAndSwallow hybrid = new ParrotAndSwallow();
BirdIF asBird = (BirdIF) hybrid;
ParrotIF asParrot = (ParrotIF) hybrid;
SwallowIF asSwallow = (SwallowIF) hybrid;
}