• 2022-06-01
    下列程序运行结果是 。class A{public:virtual void funcl(){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-]funcl();p->func2();return 0;}
  • A1A2

    举一反三

    内容

    • 0

      写出程序运行结果:_________ #include <iostream.h> class Bas { public: ~Bas() { cout<<"Bas construct"<<endl; } virtual void f()=0; }; class Dev:public Bas { public: ~Dev() { cout<<"Bas construct"<<endl; } virtual void f() { cout<<"Dev::f"<<endl; } }; void main() { Bas *a; Dev p; a=&p; a->f(); }

    • 1

      以下程序的执行结果是______ #include<iostream.h> void func(int); void main() { int k=4 func(k) ; func(k) : cout<<end1; } void func(int a) { static int m=0; m+=a; cout<<m<<" "; }

    • 2

      下面程序的运算结果是( )。 #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

    • 3

      写出下列程序的运行结果。 #include<iostream. h> class X{ public: virtual void disp(){cout<<”X类的disp函数<<”end1;} }; class Y:public X{ public: void disp(){cout<<”Y类的disp函数<<”end1;} }; void main(){ X a, *p=&a; Y b; p->disp(); p=&b; p->disp(); } 运行结果为: &#91;14&#93; &#91;15&#93;

    • 4

      有类定义如下 class A{ public: void func const { }; static void func1 { }; void func2 { } private: int i = 0; }; 则哪个语句块的语法是非法的?