第四章单元测试
- 以下不属于构造函数特征的是 ( )
- 在下面有关析构函数特征的描述中,正确的是 ( )
- 构造函数是在( )时被执行的 ( )
- 假定C为一个类,则执行C x;语句时将自动调用该类的 ( )
- 利用类Image定义一个指针变量p_img,并为p_img动态获取10个内存空间的语句为 p_img = new Image[10]; 要释放p_img所指向的动态内存,应使用语句delete[] p_img; ( )
- If default constructor is not defined, then how the objects of the class will be created? ( )
- #include <stdio.h>
class Data{
public:
int x;
Data(){
printf("Hello");
}
};
void main(){
Data d;
}
Output? ( ) - #include <stdio.h>
class Test
{
public:
Test() { x = 5;}
int x;
};
void main()
{
Test *t = new Test;
printf("%d", t->x);
}
Output? ( ) - #include <stdio.h>
class sample{
public:
sample(){
printf("Hi ");
}
~sample() {
printf("Bye");
}
};
int main() {
sample *obj = new sample();
delete(obj);
return 0;
}
Output? ( )
A:构造函数可以重载 B:构造函数必须指定返回类型 C:构造函数可以设置缺省参数 D:构造函数的函数名与类名相同
答案:构造函数必须指定返回类型
A:析构函数不能指定返回类型 B:析构函数可以有一个或多个参数 C:析构函数与类名完全相同 D:一个类可以有多个析构函数
A:创建对象 B:创建类 C:程序装入内存 D:程序编译
A:无参构造函数 B:有参构造函数 C:赋值构造函数 D:拷贝构造函数
A:对 B:错
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
A:Compilation Error B:No output C:Hello D:(Empty)
A:Compiler Error B:x C:0 D:5
A:Hi B:No output C:Bye D:Hi Bye
温馨提示支付 ¥3.00 元后可查看付费内容,请先翻页预览!