package com.homework5; public interface Compute { //声明抽象方法 int computer(int n,int m); }
package com.homework5; public class jia implements Compute { @Override public int computer(int n, int m) { return n+m; } }
package com.homework5; public class jian implements Compute { @Override public int computer(int n, int m) { return n-m; } }
package com.homework5; public class cheng implements Compute { @Override public int computer(int n, int m) { return n*m; } }
package com.homework5; public class chu implements Compute { @Override public int computer(int n, int m) { return n/m; } }
package com.homework5; public class UseCompute { public void useCom(Compute com, int one, int two) { System.out.println(com.computer(one, two)); } }
package com.homework5; public class E { public static void main(String[] args) { UseCompute uc= new UseCompute(); uc.useCom(new jia(), 5, 8); uc.useCom(new jian(), 2, 8); uc.useCom(new cheng(), 5, 8); uc.useCom(new chu(), 40, 8); } }
时间: 2024-10-24 11:35:40