问题 问答题

[说明]
下面代码实现class C对class A和B的protected成员和public成员的调用。仔细阅读[代码5-1]、[代码5-2],在 (n) 处写出正确的运行结果。
[代码5-1]
#include <iostream.h>
class A {
private:
int a1;
protected:
int a2;
public:
A ( int v1,int v2,int v3 ): a1 ( v1 ) ,a2 ( v2 ) ,a3 ( v3 )
{}
int a3
};
class B : pubiic A{
private:
int b1;
protected:
int b2;
public:
B ( int v1,int v2,int v3,int v4,int v5,int v6 )
: A(v1,v2,v3),b1 (v4),b2(v5),b3 (v6) {}
int b3;
};
class C : public B{
private:
int c1;
protected:
int c2;
public:
int c3;
C (int v1,int v2,int v3,int v4,int v5,int v6,int v7,int v8,int v9 )
: B ( v1,v2,v3,v4,v5,v6 ) ,c1 ( v7 ),c2 ( v8 ) ,c3 v9
void disp ( )
{
cout << "a2 in class C =" << a2 << endl;
cout << "a3 in class C =" << a3 << eudl;
cout << "b2 in class C =" << b2 << endl;
tout << "b3 in class C =" << b3 << endl;
}
};
[代码5-2]
voidmain()
{
Cdemo(10,20,30,40,50,60,70,80,90);
cout<<"对象demo.a3="<<demo.a3< cout<<"对象demo.b3="<<demo.b3< cout<<"对象demo.c3="<<demo.c3< demo.disp( );
}
[运行结果]
对象demo.a3= (1)
对象demo.b3= (2)
对象demo.c3= (3)
a2 in class C= (4)
a3 in class C= (5)
b2 in class C= (6)
b2 in class C= (7)

答案

参考答案:

解析:(1) 30(2) 60(3) 90(4) 20(5) 30(6) 50(7) 60 本题代码定义了class C、class A和class B。其印class B继承了class A,class C又继承了class B,class C对 class A和B的protected成员和public成员的调用。明白了这个关系就不难解题了。

单项选择题
选择题