有如下程序:
include<iostream>
using namespace std;
class A
{
public:
virtual void f(){cout<<"1";}
};
class B:public A
{
public:
B (){cout<<"2";}
};
class C:public B
{
public:
virtual void f(){B::f();cout<<"3";}
};
int main()
{
A aa,*p;
B bb;
C cc;
p=&cc;
p->f();
return 0;
}
执行上面程序的输出是______。
第1题:
有如下程序: #include <iostream> using namespace std; class Base { public: Base(){ cout<<"BB";f(); } void f() { cout<<"Bf";} }; class Derived:public Base { public: Derived() { cout<<"DD"; } void f(){ cout<<"Df"; } }; int main(){ Derived d; return 0;}执行上面的程序将输出______ 。
A.BBBfDD
B.BBDfDDDf
C.DD
D.DDBBBf
第2题:
有如下程序:
inClude<iostream>
using namespace std;
class AA
{
public:
viltual void f()
{
cout<<"AA";
}
};
class BB:public AA
{
public:
BB()
{
cout<<"BB";
}
};
class CC:public BB
{
public:
virtual void f()
{
BB::f();
cout<<"CC";
}
};
int main()
{
AA aa,*p;BB bb;CC cc;
p=&cc;
p->f();
return 0;
}
运行后的输出结果【 】。
第3题:
第4题:
有如下程序: #include<iostream>#include<iosream> using namespace std; class BASE{ char c; public; BASE(char n):c(n){} virtual ~ BASE(){cout<<c;} }; class DERIVED; public BASE{ char c; public: DERIVED (char n): BASE (n+1)
A.XY
B.YX
C.X
D.Y
第5题:
有如下程序: #include<iostream> using namespace std; class B{ public: Virtual void show(){cout<<“B”;} }; class D:publicB{ public: void show(){cout<<“D”;} }; void funl(B*ptr){ptr->show();} void{un2(B&ref){ref.show();} void
A.BBB
B.BBD
C.DBB
D.DBD