日期:2014-05-20 浏览次数:20707 次
package myTable; import java.util.ArrayList; interface IStack{ void push(int a); void pop(); int getPeak(); } public class ObjectAdapter implements IStack{ ArrayList adaptee; public void push(int a){ adaptee.add(a); } public void pop(){ adaptee.remove(adaptee.size()-1); } public int getPeak(){ return (Integer) adaptee.get(adaptee.size()-1); } }
interface athlete{ void run(); void swim(); void dive(); } public abstract class athleteAdapter implements athlete{ public void run(){ } public void swim(){ } public void dive(){ } } class athletes extends athleteAdapter{ public void run(){ System.out.println("Start running!"); } } class swimmer extends athleteAdapter{ public void swim(){ System.out.println("Start swimming!"); } } class diver extends athleteAdapter{ public void dive(){ System.out.println("Start diving!"); } }
------解决方案--------------------
7楼的看起来更一目了然
------解决方案--------------------
学习学习!
------解决方案--------------------
学习ing
------解决方案--------------------
组合优先于继承