多选题Given: Which five methods, inserted independently at line 5, will compile?()Aprotected int blipvert(long x) { return 0; }Bprotected long blipvert(int x) { return 0; }Cprivate int blipvert(long x) { return 0; }Dprivate int blipvert(int x) { return 0; }E

题目
多选题
Given: Which five methods, inserted independently at line 5, will compile?()
A

protected int blipvert(long x) { return 0; }

B

protected long blipvert(int x) { return 0; }

C

private int blipvert(long x) { return 0; }

D

private int blipvert(int x) { return 0; }

E

public int blipvert(int x) { return 0; }

F

protected long blipvert(long x) { return 0; }

G

protected long blipvert(int x, int y) { return 0; }


相似考题
更多“多选题Given: Which five methods, inserted independently at line 5, will compile?()Aprotected int blipvert(long x) { return 0; }Bprotected long blipvert(int x) { return 0; }Cprivate int blipvert(long x) { return 0; }Dprivate int blipvert(int x) { return 0; }E”相关问题
  • 第1题:

    有如下程序: include using namespace std; class Sample { frien

    有如下程序: #include <iostream> using namespace std; class Sample { friend long fun(Sample s); public: Sample(long a) {x=a;} private: long x; }; long fun(Sample s) { if(s.x < 2) return 1; return s.x * fun(Sample(s.x-1)); } int main() { int stun = 0; for (int i=0; i<6; i++) {sum += fun(Sample(i));} cout << sum; return 0; }运行时输出的结果是

    A.120

    B.16

    C.154

    D.34


    正确答案:C
    解析:本题考查的知识点是:友元函数、递归函数。友元函数不是当前类的成员函数,而是独立于当前类的外部函数,但它可以访问该类的所有对象的成员,包括私有成员、保护成员和公有成员。本题中的fun函数就被声明为Sample类的友元函数了。因此,在fun函数中可以直接访问Sample类对象的私有成员x。主函数中通过一个for循环依次以临时构造的Sample类对象为参数,调用fun函数,构造参数依次为0~5。如果一个函数在其函数体内直接或间接地调用了自己,该函数就称为递归函数。本题中的fun()函数直接调用了自身,所以它又是递归函数,不难分析其递归性质如下:

    因为Sample类的构造函数只是简单的将构造参数a赋给成员x,故可省略不看。通过上述递归定义不难看出,n取0~5时,fun(n)的值依次为:1,1,2,6,24,120。累加之后结果为154,故本题应该选择C。

  • 第2题:

    Given:Which code, inserted at line 15, allows the class Sprite to compile?()

    A.Foo { public int bar() { return 1; }

    B.new Foo { public int bar() { return 1; }

    C.new Foo() { public int bar() { return 1; }

    D.new class Foo { public int bar() { return 1; }


    参考答案:C

  • 第3题:

    下列程序的输出结果是()。 include int fun(int x) {int a;if(x==0‖x==1) return 3;els

    下列程序的输出结果是( )。 #include<stdio.h> int fun(int x) { int a; if(x==0‖x==1) return 3; else a=x-fun(x-2); return a; } void main() { printf("%d",fun(7)); }

    A.2

    B.8

    C.9

    D.5


    正确答案:A
    解析:本题考查函数的递归调用。在函数递归调用时,fun(7):a=7-fon(5)→fun(5):a=5-fon(3)→fun3:a=3-fun(1)→fun(1):a=3,反推回去 fun(3):a=3-3=0→fun(5):a=5-0=5→fun(7):a=7-5-2,最后的计算结果为2。

  • 第4题:

    有以下程序:includeusing namespace std;int f(int x);int sum(int n){ int x,s=0; f

    有以下程序: #include<iostream> using namespace std; int f(int x); int sum(int n) { int x,s=0; for(x = 0;x<=n;x++) s+=f(x); return s; } int f(int x) { return (x*x+1); } int main() { int a,b; cout<<"Enter a integer number:"; cin>>a; b=sum(a) ; cout<<a<<","<<b<<end1; return 0; } 如果输入数字3,其输出结果是( )。

    A.3,12

    B.3,16

    C.3,18

    D.4,20


    正确答案:C
    解析:这还是有关调用函数的程序,而且有两层关系。根据程序逐步分析:①本程序包含了3个函数,其中主函数main调用了sam()函数,而在sum()函数中又调用了f函数。②在主函数中,先从键盘输入一整数,并赋值给a。在这里题目开始已给出输入的是整数3,调用函数sum(),并把3传值给形参n,最后输出a,b的值。③在sum()函数中,有一个for循环语句,在每次循环时调用函数f,并把当前的x值传给形参x,循环结束后,返回s值。④在f()函数中,变量x接收实参的值后,执行表达式“x*x+1”,并返回表达式的运算结果。⑤在sum()函数中,由于n值为3,不难看出,当x=0、x=1、x=2和x=3时,都能执行循环体,即调用函数f,第1次循环更改s值为1,第2次循环更改s值为3,第3次更改为8,第4次更改为18,也就是最后一次循环,即最终sum()返回值将是18。⑥在主函数收到sum()函数的返回值,并输出3,18。

  • 第5题:

    下列程序的输出结果是()。includeint fun(int x){int p; if(x==0‖x==1)return 3; elsep

    下列程序的输出结果是( )。 #include<stdio.h> int fun(int x) { int p; if(x==0‖x==1) return 3; else p=x-fun(x-2); return p; } void main() { printf("\n%d",fun(5)); }

    A.5

    B.3

    C.7

    D.1


    正确答案:A
    解析: 本题考查函数的递归调用。在函数递归调用时,fun(5):a=5-fun(3)->fun3:a=3-fun(1)->fun(1):a=3,反推回去fun(3):a=3-3=0->fun(5):a=5-0=5,最后的计算结果为5。

  • 第6题:

    下列程序的输出结果是()。includeint fun(int x){ int a;if(x==0||x=1)return 3;elsea=

    下列程序的输出结果是( )。#include<stdio.h>int fun(int x){ int a; if(x==0||x=1) return 3; else a=x-fun(x-2); return a;}void main(){ printf("%d",fun(7));}

    A.2

    B.8

    C.9

    D.5


    正确答案:A
    解析:本题考查函数的递归调用。在函数递归调用时,fun(7):a=7-fun(5)→fun(5):a=5-fun(3)→fun3:a=3-fun(1)→fun(1):a=3,反推回去fun(3):a=3-3→0→fun(5):a=5-0=5→fun(7):a=7-5=2,最后的计算结果为2.

  • 第7题:

    下列程序的输出结果是()。 include int fun(int x) {int p; if(x==0‖x=1) return 3; e

    下列程序的输出结果是( )。

    #include<stdio.h>

    int fun(int x)

    { int p;

    if(x==0‖x=1)

    return 3;

    else

    p=x-fun(x-2) ;

    return p;

    }

    void main()

    { printf("\n%d",fun(5) );

    }

    A.5

    B.3

    C.7

    D.1


    正确答案:A
    解析:本题考查函数的递归调用。在函数递归调用时,fun(5):a=5-fun(3)->fun3:a=3-fun(1)->fun(1):a=3,反推回去fun(3):a=3-3=O->fun(5):a=5-0=5,最后的计算结果为 5。

  • 第8题:

    class A {  protected int method1(int a, int b) { return 0; }  }  Which two are valid in a class that extends class A?() 

    • A、 public int method1(int a, int b) { return 0; }
    • B、 private int method1(int a, int b) { return 0; }
    • C、 private int method1(int a, long b) { return 0; }
    • D、 public short method1(int a, int b) { return 0: }
    • E、 static protected int method1(int a, int b) { return 0; }

    正确答案:A,C

  • 第9题:

    1. class Over{   2. int doIt(long x) { return 3;}   3. }   4.   5. class Under extends Over{   6. //insert code here 7. }   和四个方法:   short doIt(int y) {return 4;}   int doIt(long x,long y){return 4;}   private int doIt(Short y){ return 4;}   protected int doIt(long x){return 4;}   分别插入到第6行,有几个可以通过编译?()  

    • A、2
    • B、3
    • C、4
    • D、0
    • E、1

    正确答案:C

  • 第10题:

    1. public class Blip {  2. protected int blipvert(int x) { return 0; }  3. }  4. class Vert extends Blip {  5. // insert code here  6. }  Which five methods, inserted independently at line 5, will compile?()  

    • A、 public int blipvert(int x) { return 0; }
    • B、 private int blipvert(int x) { return 0; }
    • C、 private int blipvert(long x) { return 0; }
    • D、 protected long blipvert(int x, int y) { return 0; }
    • E、 protected int blipvert(long x) { return 0; }
    • F、 protected long blipvert(long x) { return 0; }
    • G、protected long blipvert(int x) { return 0; }

    正确答案:A,C,D,E,F

  • 第11题:

    多选题
    Given: Which five methods, inserted independently at line 5, will compile?()
    A

    protected int blipvert(long x) { return 0; }

    B

    protected long blipvert(int x) { return 0; }

    C

    private int blipvert(long x) { return 0; }

    D

    private int blipvert(int x) { return 0; }

    E

    public int blipvert(int x) { return 0; }

    F

    protected long blipvert(long x) { return 0; }

    G

    protected long blipvert(int x, int y) { return 0; }


    正确答案: D,B
    解析: 暂无解析

  • 第12题:

    多选题
    class A {  protected int method1(int a, int b) { return 0; }  }  Which two are valid in a class that extends class A?()
    A

    public int method1(int a, int b) { return 0; }

    B

    private int method1(int a, int b) { return 0; }

    C

    private int method1(int a, long b) { return 0; }

    D

    public short method1(int a, int b) { return 0: }

    E

    static protected int method1(int a, int b) { return 0; }


    正确答案: D,B
    解析: 暂无解析

  • 第13题:

    下面函数的作用是【 】。

    int index(int x,int a[],int n)

    {

    for(int i=0;i<n;i++)

    {

    if(a[i]==x)

    return i;

    }

    return i;

    }


    正确答案:数组a中查找x若有则返回第一个x的下标若没有则返回n
    数组a中查找x,若有则返回第一个x的下标,若没有则返回n 解析:函数的作用是通过变量数组,在数组中查找x,若找到则显示下标i。

  • 第14题:

    下列程序的输出结果是()。 include int fun(int x) {int a; if(x==0‖x==1) return 3;

    下列程序的输出结果是( )。

    #include<stdio.h>

    int fun(int x)

    { int a;

    if(x==0‖x==1)

    return 3;

    else

    a=x-fun(x-2) ;

    return a;

    }

    void main()

    { printf("%d",fun(7) );

    }

    A.2

    B.8

    C.9

    D.5


    正确答案:A
    解析:本题考查函数的递归调用。在函数递归调用时,fun(7):a=7-fun(5)→fun(5):a=5-fun(3)→ fun3:a=3-fun(1)→fun(1):a=3,反推回去fun(3):a=3-3=0→ fun(5):a=5-0=5→fun(7):a=7-5=2,最后的计算结果为2。

  • 第15题:

    下列程序的运行结果是______。includelong func(int x){ long p;if(x==O‖x==1)return(1)

    下列程序的运行结果是______。

    include<stdio.h>

    long func(int x)

    { long p;

    if(x==O‖x==1)

    return(1);

    p=x*func(x-1);

    return(p);

    }

    main()

    { printf("%d\n",func(4));

    }


    正确答案:

    本题考查函数的循环调用。p=x*func(x-1),当x=4时,不满足if语句的条件,p=4*func(3), x=3也不满足条件,则func(3)=3*func(2),func(2)=2*func(1),x=1满足条件return(1),则输出结果为 4*3*2*1=24。

  • 第16题:

    有如下程序: #inClude<iostream> using namespaCe std; Class Sample{ friend long fun(Sample S); publiC: Sample(10ng A.{x=a;} private: long X; }; long fun(Sample S){ if(S.x<2)return l; return S.X*fun(Sample(s.x-1)); } int main( ) { int sum=0; for(int i=0;i<6;i++) {sum+=fun(Sample(i));} Cout<<sum: return 0; } 执行这个程序的输出结果是( )。

    A.120

    B.16

    C.154

    D.34


    正确答案:C
    本题考查默认构造函数,当i=0、1时,fun(Sample(i))为1;当i=2时,fun(Sample(i)1为2;当i=3时,fun(Sample(i))为6;当i=4时,fun(Sample(i))为24;当i=5时,fun(Sample(i))为120。所以总和为l54

  • 第17题:

    有以下程序includeint f(intx){inty; if(x==0||x==1)return(3); y=x*x-f(x-2); return

    有以下程序 #include <stdio.h> int f(int x) { int y; if(x==0||x==1) return(3); y=x*x-f(x-2); return y; } main() { int z; z=f(3); printf("%d\n",z); } 程序的运行结果是

    A.0

    B.9

    C.6

    D.8


    正确答案:C
    解析:函数int f(int x)是一个递归函数调用,当x的值等于0或1时,函数值等于3,其他情况下y=x2-f(x -2),所以在主函数中执行语句z=f(3)时,y=3*3-f(3-2)=9-f(1)=9-3=6。

  • 第18题:

    下列程序的输出结果是( )。 include int fun(int x) {int p;if(x==0‖x==1) return 3;el

    下列程序的输出结果是( )。 #include<stdio.h> int fun(int x) { int p; if(x==0‖x==1) return 3; else p=x-fun(x-2); return p; } void main() { print f("\n%d", fun(5)); }

    A.5

    B.3

    C.7

    D.1


    正确答案:A
    解析:本题考查函数的递归调用。在函数递归调用时,fun(5):a=5-fun(3)->fun3=a=3-fun(1)->fun(1):a-3,反推回去 fun(3):a=3-3=0->fun(5):a=5-0=5,最后的计算结果为5。

  • 第19题:

    有如下程序: include using namespace std; int fun1(int x) {return++x;} int fun2(i

    有如下程序:

    include<iostream>

    using namespace std;

    int fun1(int x) {return++x;}

    int fun2(int &x) {return++x;}

    int main(){

    int x=1,y=2;

    y=fun 1(fun2(x));

    cout<<X<<','<<y;

    return 0:

    }

    程序的输出结果是______。


    正确答案:23
    2,3 解析:此题考查的是函数传值。int fun1(int x) {retum++x;}函数中参数为传值,所以对于函数的操作不会改变实参的值,而函数int fun2(int &x){retum++x;}中的参数为引用,对于形参的操作会改变实参的值。在主函数中调用fun2(x)后,变量x的值修改为2,所以在调用fun1函数时其形参值为2,即运算后y的值被赋值为3,所以输出为2,3。

  • 第20题:

    Given the following code, which method declarations, when inserted at the indicated position, will not cause the program to fail compilation?()   public class Qdd1f {   public long sum(long a, long b) {  return a + b;  }   // insert new method declaration here  }  

    • A、public int sum(int a, int b) { return a + b; }
    • B、public int sum(long a, long b) { return 0; }
    • C、abstract int sum();
    • D、private long sum(long a, long b) { return a + b; }
    • E、public long sum(long a, int b) { return a + b; }

    正确答案:A,E

  • 第21题:

    现有:  1.class Over  {  2.int dolt (long x)  {  return 3;  }      3.  }      4.  5. class Under extends Over  {      6.//insert code here      7.  }  和四个方法:  short dolt (int y)  {  return 4;  }  int dolt(long Xr long y)  {  return 4;  }      private int dolt(short y)  {  return 4;  }     protected int dolt (long x)  {  return 4;  }      分别插入到第6行,有几个可以通过编译?()     

    • A、  1
    • B、  2
    • C、  3
    • D、  4

    正确答案:D

  • 第22题:

    多选题
    Given the following code, which method declarations, when inserted at the indicated position, will not cause the program to fail compilation?()   public class Qdd1f {   public long sum(long a, long b) {  return a + b;  }   // insert new method declaration here  }
    A

    public int sum(int a, int b) { return a + b; }

    B

    public int sum(long a, long b) { return 0; }

    C

    abstract int sum();

    D

    private long sum(long a, long b) { return a + b; }

    E

    public long sum(long a, int b) { return a + b; }


    正确答案: B,C
    解析: 暂无解析

  • 第23题:

    多选题
    1. public class Blip {  2. protected int blipvert(int x) { return 0; }  3. }  4. class Vert extends Blip {  5. // insert code here  6. }  Which five methods, inserted independently at line 5, will compile?()
    A

    public int blipvert(int x) { return 0; }

    B

    private int blipvert(int x) { return 0; }

    C

    private int blipvert(long x) { return 0; }

    D

    protected long blipvert(int x, int y) { return 0; }

    E

    protected int blipvert(long x) { return 0; }

    F

    protected long blipvert(long x) { return 0; }

    G

    protected long blipvert(int x) { return 0; }


    正确答案: B,D
    解析: 暂无解析

  • 第24题:

    多选题
    给定java代码如下所示,在A处新增下列()方法,是对cal方法的重载。public class Test {  public void cal(int x, int y, int z) { } //A }
    A

    public int cal(int x,int y,float z){return 0;}

    B

    public int cal(int x,int y,int z){return 0;}

    C

    public void cal(int x,int z){}

    D

    public viod cal(int z,int y,int x){}


    正确答案: B,D
    解析: 暂无解析