第四章单元测试
  1. 以下不属于构造函数特征的是 ( )

  2. A:构造函数可以重载 B:构造函数必须指定返回类型 C:构造函数可以设置缺省参数 D:构造函数的函数名与类名相同
    答案:构造函数必须指定返回类型
  3. 在下面有关析构函数特征的描述中,正确的是 ( )

  4. A:析构函数不能指定返回类型 B:析构函数可以有一个或多个参数 C:析构函数与类名完全相同 D:一个类可以有多个析构函数
  5. 构造函数是在( )时被执行的 ( )

  6. A:创建对象 B:创建类 C:程序装入内存 D:程序编译
  7. 假定C为一个类,则执行C x;语句时将自动调用该类的 ( )

  8. A:无参构造函数 B:有参构造函数 C:赋值构造函数 D:拷贝构造函数
  9. 利用类Image定义一个指针变量p_img,并为p_img动态获取10个内存空间的语句为 p_img = new Image[10]; 要释放p_img所指向的动态内存,应使用语句delete[] p_img; ( )

  10. A:对 B:错
  11. If default constructor is not defined, then how the objects of the class will be created? ( )

  12. A:Error will occur at run-time B:The compiler will generate error C:None of these D:Compiler provides its default constructor to build the object
  13. #include <stdio.h>
    class Data{
    public:
    int x;
    Data(){
    printf("Hello");
    }
    };
    void main(){
    Data d;
    }
    Output? ( )

  14. A:Compilation Error B:No output C:Hello D:(Empty)
  15. #include <stdio.h>
    class Test
    {
    public:
    Test() { x = 5;}
    int x;
    };
    void main()
    {
    Test *t = new Test;
    printf("%d", t->x);
    }
    Output? ( )

  16. A:Compiler Error B:x C:0 D:5
  17. #include <stdio.h>
    class sample{
    public:
    sample(){
    printf("Hi ");
    }
    ~sample() {
    printf("Bye");
    }
    };
    int main() {
    sample *obj = new sample();
    delete(obj);
    return 0;
    }
    Output? ( )

  18. A:Hi B:No output C:Bye D:Hi Bye

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