第八章单元测试
  1. 静态成员函数不必通过该类的对象调用,可以直接用类名以及作用域运算符::进行调用。 ( )

  2. A:对 B:错
    答案:对
  3. 关于类的静态成员的不正确描述是 ( )

  4. A:静态成员函数不拥有this指针,需要通过类参数访问对象成员 B:静态数据成员要在类外定义和初始化 C:静态成员不属于对象,是类的共享成员 D:只有静态成员函数可以操作静态数据成员
  5. 若有以下说明,则对n的正确访问语句是( )
    class Y{
    public:
    static int n;
    };
    intY::n;
    Y objY;

  6. A:Y::n=1; B:n=1; C:objY::n=1; D:Y->n
  7. const表示常量,类的const数据成员初始化只能在成员初始化列表里。( )

  8. A:错 B:对
  9. const int *p说明不能修改( )


  10. A:p指针指向的变量; B:p指针; C:p指针指向的数据类型;
  11. The lifetime of a static member variable is same as ___( )

  12. A:The private of variable of any object B:Lifetime of the program C:The public variable of any object D:The first object of its class
  13. #include <stdio.h>
    class Test{
    static int x;
    public:
    Test() { x++; }
    static int getX() {return x;}
    };
    int Test::x = 0;
    void main(){
    printf("%d ", Test::getX());
    Test t[5];
    printf("%d ", Test::getX());
    }
    Output? ( )

  14. A:5 5 B:0 5 C:0 0 D:5 0
  15. #include <stdio.h>
    class Player{
    private:
    int id;
    static int next_id;
    public:
    int getID() { return id; }
    Player() { id = next_id++; }
    };
    int Player::next_id = 1;
    void main(){
    Player p1;
    Player p2;
    Player p3;
    printf("%d ", p1.getID());
    printf("%d ", p2.getID());
    printf("%d ", p3.getID());
    }
    Output? ( )

  16. A:1 2 3 B:1 1 1 C:1 3 1 D:2 2 2
  17. #include <stdio.h>
    int main(){
    const int x;
    x = 10;
    printf("%d", x);
    return 0;
    }
    Output? ( )

  18. A:Error B:10 C:Garbage value
  19. #include <stdio.h>
    class Point{
    int x, y;
    public:
    Point(int i = 10, int j = 10){
    x = i;
    y = j;
    }
    int getX() const {
    return x;
    }
    int getY() {
    return y;
    }
    };
    void main(){
    const Point t;
    printf("%d %d", t.getX(), t.getY());
    }
    Output? ( )

  20. A:0 0 B:Compile error C:10 10

温馨提示支付 ¥3.00 元后可查看付费内容,请先翻页预览!
点赞(2) dxwkbang
返回
顶部