对于类定义: class A{ public: virtual void func1(){} Void func2 (){} }; class B:public A{ public: void func1(){cout<<"class B func 1"<<end1;} virtual void func2(){cout<<"class B func 2"<<end1;} };下面叙述正确的是( )。A.A::func2()和B::func1()都是虚函数B.A::func2()和B::func1()都不是虚函数C.B::func1()是虚函数,而A::func2()不是虚函数D.B::func1()不是虚函数,而A::func2()是虚函数

对于类定义: class A{ public: virtual void func1(){} Void func2 (){} }; class B:public A{ public: void func1(){cout<<"class B func 1"<<end1;} virtual void func2(){cout<<"class B func 2"<<end1;} };下面叙述正确的是( )。

A.A::func2()和B::func1()都是虚函数
B.A::func2()和B::func1()都不是虚函数
C.B::func1()是虚函数,而A::func2()不是虚函数
D.B::func1()不是虚函数,而A::func2()是虚函数

参考解析

解析:继承是面向对象程序设计最重要的特征,指的是一个新类从已有的类那里获得其已有的特征,并可以添加新的特征。虚函数的作用是允许在派生类中重新定义与基类同名的函数,并且可以通过基类指针或引用来访问基类和派生类中的同名函数。题中类A声明了两个函数,一个虚函数func1()和一个函数func2(),类B继承于类A,那就继承了类A的特征,因此,类B中的func1()是一个虚函数。在类B中又把func2()声明成虚函数,给func2()增加了新的特征,所以,类B中的两个函数都是虚函数,而在类A中只有func1()是虚函数。

相关考题:

有如下程序#includeusing 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.B1B2B.A1A2C.B1A2D.A1B2

( 35 ) 有如下程序#includeusing 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) B1B2B) A1A2C) B1A2D) A1B2

有如下程序: include using namespace std; class A { public: virtual void f(){cout 有如下程序: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;}执行上面程序的输出是______。

对于类定义: class A{ public: virtual void func1( ){} void func2( ){} }; class B:public A{ public: void func1(){cout<<"class B func 1"<<end1;} virtual void func2(){cout<<"class B func 2"<<end1;} }; 下面叙述正确的是(53)。A.A∷func2()和B∷func1()都是虚函数B.A∷func2()和B∷func1()都不是虚函数C.B∷func1()是虚函数,而A∷func2()不是虚函数D.B∷func1()不是虚函数,而A∷func2()是虚函数

对于类定义class A{public:virtual void funcl(){}void func2(){}};class B:public A{public:void funcl(){cout "class B func 1”virtual void func2(){cout "class B func 2"};下面正确的叙述是A.A::func2()和B::funcl()都是虚函数B.A::func2()和B::funcl()都不是虚函数C.B::funcl()是虚函数,而A::func2()不是虚函数D.B::funcl()不是虚函数,而A::func2()是虚函数

对于类定义class A{public:virtual void func1( ) {}void func2( ) {}};class B: public A{public:void func1( ) {cout < < "class B func 1" < < endl;}virtua1 void func2( ) {cout < < "class B func 2" < < endl;}};下面正确的叙述是A.A: :func2( ) 和B: :func1( ) 都是虚函数B.A: :func2( ) 和B: :func1( ) 都不是虚函数C.B: :func1( ) 是虚函数,而A: :func2( ) 不是虚函数D.B: :func1( ) 不是虚函数,而A: :func2( ) 是虚函数

请将下列类定义补充完整class Base{public: void fun(){cout<<"Base::fun"<<end1;}};class Derived:public Base{public:void fun(){______//显式调用基类的fun函数cout<<"Derived::fun"<<end1;}};

有如下程序: include using namespace std; class ONE { public: virtual void f() { 有如下程序: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;}执行上面程序的输出是【 】。

有如下程序include using namespace std;class A{public:virtual void func1 (){ cou 有如下程序#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.B1B2B.A1A2C.B1A2D.A1B2

对于类定义 class A{ public: void func2{} }; class B:public A{ public: w)id funcl| cout"class B func l”endl:} virtual voiIl fimc2{cout"class B func 2" endl:} }; 下面正确的叙述是( )。A.A::rune2和B::funcl都是虚函数B.A::func2和B::funel都不是虚函数C.B::funcl是虚函数,而A::func2不是虚函数D.B::funcl不是虚函数,而A::func2是虚函数

对于类定义: class A{ public: virtual void funcl(){} void func2(){} ); class B:public A{ public: voidfuncl(){cout<<“class Bfunc 1”<<endl;} virtual void func2(){cout<<“class B func 2”<<endl;} }; 下面正确的叙述是( )。A.A::func2()和B::funcl()都是虚函数B.A::func2()和B::funcl()都不是虚函数C.B::funcl()是虚函数,而A::func2()不是虚函数D.B::funcl()不是虚函数,而A::func2()是虚函数

下列程序的运行结果是______。 include class A { public: virtual void use( ) {cou 下列程序的运行结果是______。include<iostream.h>class A{public:virtual void use( ) {cout<<"in A\n";}};class B:public A{public:virtual void use( ) {cout<<"in B\n";}};class C:public B{public:virtual void use( ){cout"in C\n";}};void main( ){A*obj;bj=new C;obj->use( );delete obj;}

对于类定义 classA{ public: virtual void func1(){} void func2(){} }; Class B:public A{ public: void funcl(){cout <<”class B func1” <<end1;} virtual void func2(){cout <<"class B func 2" <<end1;} }; 下面正确的叙述是A.A∷func2()和B∷funcl()都是虚函数B.A∷func2()和B∷funcl()都不是虚函数C.B∷funcl()是虚函数,而A∷func2()不是虚函数D.B∷funcl()不是虚函数,而A∷func2()是虚函数

以下程序的执行结果是______。 include class A{ int a: public: void seta(int x) { 以下程序的执行结果是______。include<iostream.h>class A{int a:public:void seta(int x) {a=x;}void showa() {cout<<a<<end1;}};class B{int b;public:void setb(int x) {b=x;}void showb(){cout<<b<<end1;}};

下面程序执行后的结果是()。includeusing namespace std;void func1(int i);void func 下面程序执行后的结果是( )。 #include<iostream> using namespace std; void func1(int i); void func2(int i); char st[]="hello, friend!"; void func1(int i) { cout<<st[i]; if(i<3){i+=2;func2(i);} } void func2(int i) { cout<<st[i]; if(i<3){i+=2;func1(i);} } void main() { int i=0;func1(i);cout<<endl;}A.elloB.helC.hloD.him

若有以下程序: include using namespace std; class Base { public:void who(){ cout 若有以下程序:include <iostream>using namespace std;class Base{public:void who(){cout<<"class Base"<<end1;}};class Derivedl : public Base{public:void who(){cout<<"class Derivedl"<<end1;}};class Derived2 : public Base{public:void who(){cout<<"class Derived2"<<end1;}};int main(){Base *p;Derivedl obj1;Derived2 obi2;p=obj 1;p=obj2;p->who ( );return 0;}则该程序运行后的输出结果是【 】。

有如下程序:includeusing namespace std;class A{public:virtual void func1(){cout 有如下程序: #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.B1B2B.A1A2C.B1A2D.A1B2

有下列程序:includeusing namespace std;class ONE{ public:virtual void f(){COUt 有下列程序: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

写出下列程序代码运行的结果【】。 include class A{public:virtual void disp() {cout 写出下列程序代码运行的结果【 】。include<iostream.h>class A{public:virtual void disp() {cout<<" calss A!" <<(end1;}}:class B: public A{public:void disp() {cout<<" class B! " <<end1:}};class C: public A{public:void disp() {cout<<"class C! " (<end1;}};void main() {A a, *ptr;B b;C c;a. disp();b. disp();c. disp();ptr=b;ptr->disp();ptr=c;ptr->disp():}

对于类定义 class A{ public: virtual void func1( ){} void func2( ){} }; class B:public A{ public: void func1( ){cout<<"class B func 1"< < end1;} virtual void func2( ){cout << "class B func2"<< end1;} }; 下面正确的A.A::func2( )和B::func1( )都是虚函数B.A::func2( )和B::func1( )都不是虚函数C.B::func1( )是虚函数,而A::func2( )不是虚函数D.B::func1( )不是虚函数,而A::func2( )是虚函数

有下列程序:inCludeusing namespace std;c1ass A{pubic:virmal void func1(){cout 有下列程序: #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.B182B.A1A2C.B1A2D.A182

有以下程序:include using namespace std;class Base{public:Base(){}virtual void w 有以下程序: #include <iostream> using namespace std; class Base { public: Base(){} virtual void who() { cout<<"Base Class"<<end1; } ~Base(){} }; class Derivel : public Base { public: void who() { cout<<"Derivel Class"<<end1; } }; class Derive2 : public Base { public: void who () { cout<<"Derive2 Class"<<end1; } }; int main () { Base *p; Derivel obj1; Derive2 obj2; p=obj1; p=obj2; p->who ( ); return 0; } 执行程序后的输出结果是( )。A.Base ClassB.Derivel ClassC.Derive2 ClassD.程序编译时出错

有如下程序:includeusing namespace std;class B{public:Virtual void show(){cout 有如下程序: #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(Bref){ref.show();} voidA.BBBB.BBDC.DBBD.DBD

有如下程序:includeusing namespace std;class Base{public:virtual void func1(){co 有如下程序: #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 2B.Base 1 Base 2C.Derived 1 Derived 2D.Base 1 Derived 2

有如下程序: #includeiostream 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.B182B.A1A2C.B1A2D.AIB2

设有以下定义和程序:includeclassA1{public: void showl() { cout 设有以下定义和程序: #include <iostream.h> class A1 { public: void showl() { cout<<"class A1"<<end1; } }; Class A2 : public A1 { public: void show2() { cout<<"Class A2"<<end1; } }; Class A3 : protected A2 { public: void show3() { cout<<”Class A土”<<end1; } }; void main() { A1 obj1; A2 obj2; A3 obj3; } 则以下不合语法的调用语句是( )。A.obj1.show1();B.obj2.show1();C.obj3.show1();D.obj2.show2();

对于类定义 class A { public: virtual void funcl(){} void func2(){} }; class D:public A{ public: void funcl(){cout<< "class B rune 1"<<end1;} virtual void func2(){cout<< "class B func 2"<<end1;} }; 下面正确的叙述是 ______。A.A::func2()和B::funcl()都是虚函数B.A::func2()和B::funcl()都不是虚函数C.B::func1()是虚函数,而A::func2()不是虚函数D.B::func1()不是虚函数,而A::func2()是虚函数

下列程序的运行结果是______。 include class Base { public: virtual void func(int 下列程序的运行结果是______。include<iostream.h>class Base{public:virtual void func(int i){cout<<"class Base:"<<i<<end1;)};class Derived: public Base{public:void func(double d){cout<<"class Derived:"<<d<<endl;}};void main( ){Base a,*p=a;Derived b;p=b;(*p).func(3.3);}