第七章单元测试
  1. 若classB中定义了一个classA的类成员Aa,则在类B的成员函数中可以访问A类的保护数据成员。( )

  2. A:对 B:错
    答案:错
  3. B类中有对象A作为成员,那么当创建B对象时,则先调用A的构造函数,后调用B的构造函数。( )

  4. A:对 B:错
  5. 若有以下类T说明,则函数fFriend的错误定义是 ( )
    class T{
    int i;
    friend void fFriend(T&, int );
    };

  6. A:void T::fFriend( T &objT, int k ) { k += objT.i; } B:void fFriend( T &objT, int k ) { k = objT.i; } C:void fFriend( T &objT, int k ) { objT.i = k; } D:void fFriend( T &objT, int k ) { objT.i += k; }
  7. 关于C++中的友元函数说法正确的是( )

  8. A:友元函数是能被继承的 B:友元函数需要通过对象或指针调用 C:友元函数破环了继承性机制 D:友元函数没有this指针
  9. If class A is friend of class B and if class B is friend of class C, which of the following is true? ( )

  10. A:Class C is friend of class A B:None of the above C:Class A is friend of class C D:Class B cannot be a friend of any other class
  11. #include <stdio.h>
    class Box{
    int capacity;
    public:
    Box(int cap){
    capacity = cap;
    }
    friend void show();
    };
    void show(){
    Box b(10);
    printf("Value of capacity is %d", b.capacity);
    }
    void main(){
    show();
    }
    Output? ( )

  12. A:Value of capacity is: 0 B:Value of capacity is: C:Error D:Value of capacity is: 10
  13. #include <stdio.h>
    class Box{
    int capacity;
    public:
    Box(int cap){
    capacity = cap;
    }
    friend void show();
    };
    void Box::show(){
    Box b(10);
    printf("Value of capacity is %d", b.capacity);
    }
    void main(){
    show();
    }
    Output? ( )

  14. A:Value of capacity is: 10 B:Value of capacity is: 0 C:Error D:Value of capacity is:
  15. Why do we need relationships between classes? ( )

  16. A:All of the mentioned B:To enhance the communication between classes C:To use the functionality of one class into other D:To increase code re-usability

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