有如下程序: #included<iostream> usingnamespqcestd; classTestClass { private; charC; public; TestClass(charn):c(n){} ~TestClass() { cout<<c; } }; classTestClassl:publicTestClass { private: charC; public: TestClassl(charn):TestClass(n+1),c(n){}~TestClassl() { cout<<c; } }; intmain() { TestClasslobj(X); return0; } 执行上面的程序将输出( )。
A.xy
B.yx
C.X
D.y
第1题:
有以下程序 #include <iostream> #include <string> using namespace std; class base { private: char baseName[10]; public: base () { strcpy(baseName,"Base"); } virtual char *myName() { return baseName; } char *className() { return baseName; } }; class Derived : public base { private: char derivedName[10]; public: Derived() { strcpy(derivedName,"Derived"); } char *myName() { return derivedName; } char *className() { return derivedName; } }; void showPtr(base &p) { cout<<p.myName () <<" "<<p.className (); } int main () { base bb; Derived dd; showPtr(dd); return 0; } 运行后的输出结果为
A.Derived Base
B.Base Base
C.Derived Derived
D.Base Derived
第2题:
有下列程序: #include<iostream> using namespace std; c1ass TestClass { private; char c; public: TestClass(char n):c(n){} ~TeStClass() { cout<<c } }; class TestClass1:public TestClass {
A.xy
B.yx
C.x
D.y
第3题:
TestClass类定义如下: class TestClass { private: intid; char gender; char*phone; public: TestClass ():id(0),gender('#'),phone(NULL){) TestClass(int no,char ge='#',char *ph=NULL) {id=no;gender=ge;phone=ph;} }; 下面类对象定义语句中错误的是( )。
A.TestClass myObj(i);
B.TestClass myObj(2,"11101111155");
C.TestClass myObj(1,'m');
D.TestClass myObj;
第4题:
有如下程序: #include<iostream> using namespace std; class TestClass { private: int x,y; public: TestClass (int i,int j) { x=i; y=j; } void print() { cout<<"print1"<<end1; } void print()const { cout<<"print2"<<end1; } }; int main() { const TestClass a(1,2); a.print(); return 0; } 该程序运行后的输出结果是( )。
A.print1
B.print2
C.print1 print2
D.程序编译时出错
第5题:
有下列程序: #include<iostream> using namespace std; class TestClass { private: int x,y; public: TestClass (int i,int j) { x=i; y=j; } void print() { cout<<"printl"<<endl; } vo
A.print1
B.print2
C.pfint1 print2
D.程序编译时出错