( 12 )有如下程序:
#include <iostream>
using namespace std
class Animal{
public:
virtual char* getType () const { return "Animal" ; }
virtual char* getVoice () const { return "Voice" ; }
};
Class Dog : public Animal {
public:
char* getType ( ) const {return "Dog" ; }
char* getVoice ( ) const {return "Woof"}
};
void type ( Animal& a ) {cout<<a.getType ( ) ; }
void speak ( Animal a ) {cout<<a.getVoice ( ) ; }
int main ( ) {
Dog d; type ( d ) ; cout<<" speak" ; speak ( d ) ; cout<<endi;
return 0;
}
运行时的输出结果是【 12 】 。
第1题:
有如下程序: #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
第2题:
有以下程序: #include <iostream> using namespace std; class BASE { private: char c; public: BASE(char n):c(n);{} virtual~BASE() { cout<<c; } }; class DERIVED:public BASE { char c; p
A.XY
B.YX
C.X
D.Y
第3题:
下面程序的运行结果是( )。 #include<iostream> using namespace std; class A { public: virtual~A() { cout<<"call A::~A()"<<endl;} }; class B:public A { char * p; public: B(int i) { p=new char[i];} ~B() { delete(p); cout<<"call B::~B()"; } }; void main() { A * a=new B(8); delete a; }
A.call B::~B()call A::~A()
B.call B::~B()
C.call A::~A()
D.call A::~A()call B::~B()
第4题:
有如下程序: #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
第5题:
若有以下程序: #include<iostream> using namespace Std; Class Base {public: Base() {x=0;} int x;}; class Derivedl:virtua1 public Base {public: Derived1() {x=10;}}; class Derived2:virtual1 public Base {public: Derived2()
A.20
B.30
C.10
D.0
第6题: