public class aa { public static void playGame(GameFactory factory) { Game s = factory.getGame(); while (s.move()) ; } interface Game { boolean move(); } interface GameFactory { Game getGame(); } class Checkers implements Game { private int moves = 0; private static final int MOVES = 4; public boolean move() { print("Checkers moves " + moves); return ++moves != MOVES; } } class CheckersFactory implements GameFactory { public Game getGame() { return new Checkers();} } private void print(String string) { // TODO Auto-generated method stub print(string); } public static void main(String[] args) { playGame(new CheckersFactory());//这行出错了 }}
添加回答
举报
0/150
提交
取消