有如下程序
#include
using namespace std;
class A{
public:
virtual Void funcl(){cout<< “A1”;}
void fune2(){cout<< “A2”;}
};
class B: public A{
public:
void func1(){cout<< “B1”;}
void func2(){cout<< “B2”;}
};
Int main(){
A*p=new B;
p->funcl();
p->func2();
retum0;
}
运行程序,屏幕上将显示输出______。
A.B1B2
B.A1A2
C.B1A2
D.A1B2
第1题:
有如下程序: #include<iostream> using namespace std; class XX { protected: int k; public: XX(int n=5):k(n){}; ~XX() { cout<<"XX": } virtual void f()const=0; }; inline void XX::f()const { cout<<k+3; }; class YY:public XX { public: ~YY() { cout<<”YY”; } void f()const { cout<<k-3; XX::f(); } }; int main() { XX &p=*new YY; P.f(); delete &p; return 0: } 执行上面的程序将输出( )。
A.28XX
B.28YYXX
C.33XX
D.33XXYY
第2题:
有如下程序: #include<iostream.h> using namespace std; Class Base { public: Base(){cout<<“BB”;f();} void{(){cout<<“BF”;} }; class Derived:public Base { public: Derived(){cout<<“DD”;} void f(){cout<<“Df”;) }; int main
A.BBBfDD
B.BBDfDDDf
C.DD
D.DDBBBf
第3题:
有如下程序:
include <iostream>
using namespace std;
class ONE
{
public:
virtual void f() { cout << "1"; }
};
class TWO: public ONE
{
public:
TWO() { cout << "2"; }
};
class THREE: public TWO
{
public:
virtual void f() {TWO::f(); cout << "3"; }
};
int main()
{
ONE aa, *p;
TWO bb;
THREE cc;
p=&cc;
P->f();
return 0;
}
执行上面程序的输出是【 】。
第4题:
有如下程序#include <iostream>using namespace std;class A{public:virtual void func1 (){ cout<<"A1"; }void func2(){ cout<<"A2"; }};class B: public A{public:void func l(){ cout<<"B1"; }void func2(){ cout<<"B2"; }};int main() {A *p=new B;p->func1();p->func2();return 0;}运行此程序,屏幕上将显示输出( )。
A.B1B2
B.A1A2
C.B1A2
D.A1B2
第5题:
有如下程序: #include<iostream> using namespace std; class Base{ public: void output( ){cout<<l;} virtual void Print( ){cout<<'B';} }; class Derived:public Base{ public: void output( ){cout<<1;} void Print( ){cout<<'D';} }; int main( ){ Base*prt=new Derived; prt->output( ); prt->Print( ); delete prt; return 0; } 程序的输出结果是
A.1B
B.1D
C.2B
D.2D
第6题:
下面程序的运算结果是( )。 #include<iostream> using namespace std; class A { public: virtual void fun()=0; }; class B:public A } public: void fun() {cout<<"new file"<<" ";} }; class C:public A { public: void fun() { cout<<"open file"<<" ";} }; void main() { A a, * p; B b;C c; p=&c; p->fun(); p=&b; }
A.new file open file
B.new file new file
C.编译出错
D.open file new file
第7题:
有如下程序: #inClude<iostream> using namespaCe std; Class Base{ publiC: void output{Cout<<1;} virtual void Print{Cout<<B’;} }; Class Derived:publiC Base{ publiC: void output{Cout<<2;} void Print{Cout<<’D ;} }; int main { Base * ptr=new Derived; ptr一>output; ptr一>Print; delete ptr; retum0; } 执行这个程序的输出结果是( )。
A.1B
B.lD
C.2B
D.2D
第8题:
有如下程序: #include<iostream> using namespace std; class A{ public: virtual void func1(){cout<<"A1";} void func2(){cout<<"A2";} }; class B:public A{ public: void func1(){cout<<"B1";} void func2(){cout<<"B2";} }; int main() { A *p=new B; p->func1(); p->func2(); return 0; } 执行该程序,屏幕上将显示输出( )。
A.B1B2
B.A1A2
C.B1A2
D.A1B2
第9题:
有以下程序:
include <iostream>
using namespace std;
class A
{
public:
virtual void show()
{
cout<<"A";
}
};
class B : public A
{
public:
void show()
{
cout << "B";
}
};
void display( A * obj )
{
obj-> show();
}
int main ( )
{
A demol;
B demo2;
display( & demol );
display( & demo2 );
return 0;
}
执行后的输出结果为【 】。
第10题:
有下列程序: #inClude<iostream> using namespace std; c1ass A{ pubic: virmal void func1(){cout<<"A1";} void func2(){cout<<"A2";} }; c1ass B:public A{ publIc: void func1(){cout<<"B1";} void func2(){cout<<"B2"
A.B182
B.A1A2
C.B1A2
D.A182
第11题:
若有如下程序: #include<iostream> using namespace std; class TestClass { public: void who() {cout<<"TestClass"<<endl;} }; class TestClass1:public TestClass { public: void who(){cout<<"TestClass1"<<endl;} }; int main() { TestClass *p; TcstClass1 obj1; p=&obj1; p->who(); return 0; } 则该程序运行后的输出结果是( )。
A.TestClass1
B.TestClass
C.0
D.无输出
第12题:
有如下程序: #include<iostream> using namespace std; class A{ public: virtual void fancl{cout<<”Al”;} void func2{cout<<”A2”;} }; class B:public A{ public: void funcI{tout<<”Bl”;} void func2{tout<<”B2”;} }; intmain} A*P=new B: P—>funcl; P—>func2; delete p; return 0; } 执行这个程序的输出结果是( )。
A.B182
B.A1A2
C.B1A2
D.AIB2
第13题:
有如下程序: #include<iostream> using namespace std; classA{ public: virtua1 voidfunc1(){cout<<“A1”;} voidfunc2(){cout<<“A2”;}}; class B:publicA{ public: void funcl(){cout<<“B1”;} void func2(){cout<<“B2”;}}; intmain(){ A*p=ne
A.B1B2
B.A1A2
C.B1A2
D.A1B2
第14题:
若有如下程序: #include<iostream> using namespace std; class TestClass { public: void who(){cout<<“TestClass”<<endl;} }; class TestClassl:public TestClass { public: void who(){cout<<“TestClassl”<<endl; int main() { TestC
A.TestClassl
B.TestClass
C.0
D.无输出
第15题:
有如下程序:#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
第16题:
如下程序的输出是 #include<iostream> using namespace std; class Base{ public: Base( ){cout<<"BB";f( );} void f( ){cout<<"Bf";} }; class Derived:public Base{ public: Derived( ){eout<<"DD";} void f( ){cout<<"Df";} }; int main( ){Derived d;return 0;}
A.BBBff)D
B.BBDfDDDf
C.DD
D.DDBBBf
第17题:
有如下程序: #include<iostream> using namespace std; class B{ public: virtual void show( ){cout<<"B";} }; class D:public B{ public: void show( ){cout<<"D";} }; void funl(B*ptr){ptr->show( );} void fun2(B&ref);ref.show( );} void fun3(B b){b.show( );} int nlain( ){ B b,*P=Dew D; D d; funl(p); fun2(b); fun3(d); return 0; } 程序的输出结果是
A.BBB
B.BBD
C.DBB
D.DBD
第18题:
有如下程序: #include<iostream> using namespace std; class TestClass1 { public: virtual void fun(){cout<<"1";} }; class TestClass2: public TestClass1 { public: TestClass2(){cout<<"2";} }; class TestClass3:public TestClass2 { public: virtual void fun(){TestClass2::fun();cout<<"3";} }; int main() { TestClass 1 aa,*p; TestClass2 bb; TestClass3 cc; p=&cc; P->fun(); return 0; } 执行上面程序的输出是( )。
A.1122
B.2112
C.2213
D.2223
第19题:
有如下程序: #include <iostream> using namespace std; class AA { public: virtual void f() { cout<< "AA"; } }; class BB : public AA { public: BB() { cout << "BB"; } }; cla
A.AA
B.AABBCC
C.BBAABBCC
D.BBBBAACC
第20题:
有下列程序:
include<iostream>
using namespace std;
class ONE
{
public:
virtual void f(){COUt<<"1";}
};
c1assTWO:public ONE
{
public:
TWO(){cout<<"2";}
};
class THREE:public TWO
{
pub
第21题:
有如下程序:
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;
}
运行后的输出结果【 】。
第22题:
有如下程序: #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
第23题:
有如下程序: #include<iostream> using namespace std; class Base{ public: virtual void func1(){cout<<"Base 1";} void rune2(){cout<<"Base 2";} }; class Derived:public Base{ public: void func1(){cout<<"Derived 1";} void func2(){cout<<"Derived 2";} }; int main(){ Base *p=new Derived; P->func1(); P->func2(); return 0: } 运行此程序,屏幕上将显示输出______。
A.Derived 1 Base 2
B.Base 1 Base 2
C.Derived 1 Derived 2
D.Base 1 Derived 2