• 2022-06-06
    阅读程序题(给出【代码】注释标注的代码的输出结果)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); //【代码】}}
  • 18:20

    举一反三

    内容

    • 0

      下列选项中,( )代码替换源文件Com.java中的【代码】不会导致编译错误。public interface com{int M=200;int f();}class ImpCom implements Com{【代码】} A: public int f( ){return 100+M;} B: int f( ){return 100;} C: public double f( ){return 2.6;} D: public abstract int f( );

    • 1

      ‌程序填空:‏‌interface Com{ int M=200; int f(); } class ImpCom implements Com{ ___________________________; }‏ A: public int f(){retrun 100+M;} B: int f() {return 100;} C: public double f(){return 2.6;} D: public abstract inf f();

    • 2

      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)); } }

    • 3

      以下程序运行结果是 public class Test { public static void main(String[] args) { int a=1,b[]={2}; add(a); add(b); System.out.println(a+","+b[0]); } static int add(int x){ x++; return x; } static void add(int[] x){ x[0]++; } }

    • 4

      下列代码能否正常运行,如果能够正常运行,输出结果是什么? public class TestClass { public static void main(String[] args) { int num1=5; int num2=5; class InnerClass{ public int add(){ return num1+num2; } }; InnerClass in=new InnerClass(); System.out.println(in.add()); } }