阅读程序题(给出【代码】注释标注的代码的输出结果)interface Com {int add(int a, int b);public static int get(int n){return n;}public default int see( int n){return n;}public default int look( int n) {return n;}}class A implements Com{public int add( int a, int b) { return a + b;}public int see(int n){ return n + 1;}}public class 习题5_阅读4{public static void main( String args[ ]) {A a = new A();int m = a.add(12,6);int n = Com.get( 12);int t = a.see(6);int q = a.look(6);System.out.printf("%d:%d:%d:%d",m,n, t,q); //【代码】 }}}
举一反三
- 阅读程序题(给出【代码】注释标注的代码的输出结果)interface Com {int add( int a, int b);}abstract class People {abstract int add( int a, int b);}class Student extends People implements Com{public int add(int a,int b) {return a + b;}}public class 习题5_阅读3 {public static void main(String args[ ]) {Student stu = new Student ();Com com = stu;int m = com.add(12,6);People p = stu;int n = p.add(12,8);System.out.printf("%d:%d",m,n); //【代码】}}
- 给出下列【代码】注释标注的代码的输出结果。abstract class A {abstract int get(int a,int b);}public class E {public static void main(String args[]) {A a=new A() {public int get(int a,int b){return a+b;}};int m = a.get(2,5);a=new A() {public int get(int a,int b){return a*b;}};int n = a.get(2,5);System.out.printf("%d:%d",m,n);//【代码】}}
- E类中System.out.println的输出结果是__________、________________。interface Com{int add(int a,int b);}abstract class A{abstract int add(int a,int b);}class B extends A implements Com{public int add(int a,int b){return a+b;}}public class E{public static void main(String args[ ]){B b=new B();Com com=b;System.out.println(com.add(12,6));A a=b;System.out.println(a.add(10,5));}}
- 下列代码的输出结果是( )interface Com{ int M=100; int on();}class A implements Com{ public int on(){ return Com.M; }}public class E{ public static void main(String args[]){ Com com=new A(); int m=com.on(); System.out.println(m); }}
- 5.请说出E类中[代码1],[代码2]的输出结果依次是______ ,______ 。 interface Com { int add(int a,int b); }abstract class A { abstract int add(int a,int b);int g(int a,int b) { return a+b; }}class B extends A implements Com{ public int add(int a,int b) { return a+b; } int g(int a,int b) { return a*b; }}public class E {public static void main(String args[]) { B b = new B(); Com com = b; System.out.println(com.add(10,5)); //[代码1] A a = b; System.out.println(a.g(10,5)); }} //[代码2]