图一
从上面的设计中,我们用代码实现/** * 考试抽象类 ** @author zhonghuan */interface Exam{public void chinese();// 考语文public void math();// 考数学public void physics();// 考物理public void geolography();// 考地理}/** * 文科生实现考试抽象类,文科生不考物理 ** @author zhonghuan */class ExamForLiberalArtStu implements Exam{public void chinese(){System.out.println("考语文");}public void math(){System.out.println("考数学");}public void physics(){// "不考物理", 不用实现, 没有意义}public void geolography(){System.out.println("考地理");}}/** * 理科生实现考试抽象类,理科生不考地理 ** @author zhonghuan */class ExamForScienceStu implements Exam{public void chinese(){System.out.println("考语文");}public void math(){System.out.println("考数学");}public void physics(){System.out.println("考物理");}public void geolography(){// 理科生不考地理,不用实现没有意义}}URL地址:http://www.bianceng.cn/Programming/project/201602/49635.htm