第七章单元测试
- 若classB中定义了一个classA的类成员Aa,则在类B的成员函数中可以访问A类的保护数据成员。( )
- B类中有对象A作为成员,那么当创建B对象时,则先调用A的构造函数,后调用B的构造函数。( )
- 若有以下类T说明,则函数fFriend的错误定义是 ( )
class T{
int i;
friend void fFriend(T&, int );
}; - 关于C++中的友元函数说法正确的是( )
- If class A is friend of class B and if class B is friend of class C, which of the following is true? ( )
- #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? ( ) - #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? ( ) - Why do we need relationships between classes? ( )
A:对 B:错
答案:错
A:对 B:错
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; }
A:友元函数是能被继承的 B:友元函数需要通过对象或指针调用 C:友元函数破环了继承性机制 D:友元函数没有this指针
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
A:Value of capacity is: 0 B:Value of capacity is: C:Error D:Value of capacity is: 10
A:Value of capacity is: 10 B:Value of capacity is: 0 C:Error D:Value of capacity is:
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 元后可查看付费内容,请先翻页预览!