• 2022-06-06
    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]
  • 15:)50

    举一反三

    内容

    • 0

      public class test1 { public static int add(int a, int b) { return a+b; } public static double add(double a, double b) { return a+b; } ________________ ___________________ { ________________ ___________________ } public static void main(String[] args) { System.out.println("调用add方法:"+add(2.1,3.4,4.5)); } }

    • 1

      给出下列【代码】注释标注的代码的输出结果。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);//【代码】}}

    • 2

      关于下列代码说法正确的是( ) public class Foo{ public int add(int a,int b){ return a+b; } public static void main(String[] args){ Foo foo = null; System.out.println(foo.add(10,20)); } }

    • 3

      请写出下列程序的输出结果。class A{public int f(int x) {return x+1;}}class B extends A{public int f(int x){return x*x;}}public class E{public static void main(String args[]){A a=new B();int m=a.f(10);System. out. println(m) ;}}

    • 4

      请说出E类中【代码1】,【代码2】的输出结果。 interface A { double f(double x,double y); } class B implements A { public double f(double x,double y) { return x*y; } int g(int a,int b) { return a+b; } } public class E { public static void main(String args[]) { A a = new B(); System.out.println(a.f(3,5)); //【代码1】 B b = (B)a; System.out.println(b.g(3,5)); //【代码2】 } }