C#中的TestClass为一自定义类,其中有如下属性定义: public void Property{……} 使用以下语句创建了该类的对象,并让变量obj引用该对象。 TestClass obj=new TestClass(); 那么,可通过()方式访问类TestClass的Property属性。
第1题:
下面类的声明中的几个语句,正确的是(设定语句是主函数中的语句)( )。 class TestClass { private: int data; public: TestClass(int g_data) { data=g_data; } void show(){cout<<data<<end1;) };
A.TestClass *p;
B.TestClass m;
C.TestClass.data=8;
D.TestClass.show();
第2题:
假定TestClass为一个类,则该类的拷贝构造函数的声明语句为( )。
A.TestClass(TestClass x)
B.TestClass&(TestClass x)
C.TestClass(TestClass *x)
D.TestClass(TestClass &x)
第3题:
下列程序中横线处正确的语句是( )。 #include<iostream> using namespace std; class TestClass { public: void fun(){cout<<"TestClass::fun"<<end1;} }; class TestClass1:public TestClass { void fun() { ______//显示调用基类的函数 fun() cout<<"TestClass1::fun"<<end1; } };
A.fun();
B.TestClass.fun()
C.TestClass::fun();
D.TestClass->fun();
第4题:
有如下类说明: class TestClass{ int x; public: TestClass(int n){x=n;} }; class TestClass1:public TestClass{ int y; public: TestClass1(int a,int b); }; 在构造函数TestClass1的下列定义中,正确的是( )。
A.TestClass1::TestClass1 (int a,int b):x(a),y(b){}
B.TestClass1::TestClass1 (int a,int b):TestClass(a),y(b){}
C.TestClass1::TestClass1 (int a,int b):x(a),TestClass1(b){}
D.TestClass1::TestClass1 (int a,int b):TestClass(a),TestClass1(b){}
第5题:
类定义如下: class TestClass { public: TestClass (){cout<<1;} }; 则执行语句TestClass a,b[2] ,*p[2];后,程序的输出结果是( )。
A.11
B.111
C.1111
D.11111
第6题:
有如下程序: #include<iostream> using namespace std; class TestClass { public: virtual void fun1() { cout<<"fun1TestClass"; } virtual void fun2() { cout<<"fun2TestClass"; } }; class TestClass1:public TestClass { void fun() { cout<<"fun1TestClass1"; } void fun2(int x) { cout<<"fun2TestClass1"; } }; int main() { TestClass obj1,*p; TestClass1 obj2; p=&obj2; p->fun1(); p->fun2(); return 0; } 该程序执行后的输出结果是( )。
A.fun1TestClass1 fun2TestClass
B.fun1TestClass1 fun2TestClass1
C.fun1TestClass fun2TestClass
D.fun1TestClass fun2TestClass1
第7题:
有以下程序: #include<iostream> using namespace std; class TestClass { public: TestClass(int n){number=n;} //拷贝构造函数 TestClass(TestClass&other){number=other.number;} ~TestClass(){} private: int number; }; TestClass fun(TestClass P) { TestClass temp(p); return temp; } int main() { TestClass obj1(10),obj2(0) ; TestClass obj3(obj 1) ; obj2=fun(obj3) ; return 0: } 程序执行时,TestClass类的构造函数被调用的次数是( )。
A.2
B.3
C.4
D.5
第8题:
将下面类TestClass中的函数fun()的对象成员n值修改为100的语句应该是( )。 class TcstClass { public: TestClass(int x){n=x;} void SetNum(int n1){n=n1;} private: int n; } int fun() { TestClass*ptr=new TestClass(45); ______; }
A.TestClass(100)
B.ptr->SetNum(100)
C.SetNum(100)
D.ptr->n=100
第9题:
若有以下程序: #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; TestClass1 obj1; P=&obj1; P->who(); return 0; 则该程序运行后的输出结果是( )。
A.TestClass1
B.TestClass
C.0
D.无输出
第10题:
C#中MyClass为一自定义类,其中有以下方法定义publicvoidHello(){⋯⋯}使用以下语句创建了该类的对象,并使变量obj引用该对象:MyClassobj=newMyClass();那么,可如何访问类MyClass的Hello方法?()。
第11题:
Obj,Property;
MyClass.Property;
obj::Property;
obj.Property;
第12题:
MyClass. Property
obj. Property
TestClass. Property
obj. Property()
第13题:
有如下程序: #include<iostream> using namespace std; class TestClass{ static int i; public: TestClass(){i++;} ~TestClass(){i--;} static int getVal(){return i;} }; int TestClass::i=0; void f(){TestClass obj2;cout<<obj2.getVal();} int main(){ TestClass obj 1; f(); TestClass *obj3=new TestClass;cout<<obj3->getVal(); delete obj3;cout<<TestClass::getVal(); return 0; } 程序的输出结果是( )。
A.232
B.221
C.222
D.231
第14题:
有如下程序: #include<iostream> using namespace std; class TestClass { private; char c; public; TestClass (char n):c(n){} ~TestClass () { cout<<c; } }; class TestClass1:public TestClass { Private: char c; public: TestClass1(char n):TestClass (n+1),c(n){} ~TestClass1() { cout<<c; } }; int main() { TestClass1 obj('x'); return 0; } 执行上面的程序输出( )。
A.xy
B.yx
C.x
D.y
第15题:
有如下程序: #include<iostream> using namespace std; class TestClass1 { public: TestClass1 (){cout<<"TestClass1";} ~TestClass1 (){cout<<"~TestClass1";} }; class TestClass2:public TestClass1 { TestClass1 *p; public: Testclass2(){cout<<"TestClass2";p=new TestClass1();} ~TestClass2(){cout<<"~TestClass2";delete p;} ); int main() { TestClass2 obj; return 0; } 执行这个程序的输出结果是( )。
A.TestClass2TestClass1TestClass1~TestClass1~TestClass2~TestClass1
B.TestClass1TestClass2TestClass1~TestClass2~TestClass1~TestClass1
C.TestClass2TestClass1TestClass1~TestClass2~TestClass1~TestClass1
D.TestClass1TestClass2TestClas1~TestClass1~TestClass2~TestClass1
第16题:
在声明派生类时,如果不显示地给出继承方式,缺省的类继承方式是私有继承private。已知有如下类定义: class TestClass{ protected: void fun(){} }; class TestClass1:TestClass{}; 则TestClass类中的成员函数fun(),TestClass1类中的访问权限是( )。
A.public
B.private
C.protected
D.virtual
第17题:
若有以下程序:
include<iostream>
using namespace std;
class TestClass 1
{
public:
TestClass1()
{
X=0;
}
int x;
};
class TestClass2:virtual public TestClass1
{
public:
TestClass2()
{
x=10;
}
};
class TestClass3:virtual public TestClass 1
{
public:
TestClass3()
{
x=20;
}
};
class TestClass4:public TestClass2, protected TestClass3
{ };
int main()
{
TestClass4 obj;
cout<<obj.x<<end1;
return 0:
}
该程序运行后的输出结果是______。
第18题:
若有如下程序: #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.无输出
第19题:
下面的类定义中,如果要为其添加一个析构函数,对于析构函数定义正确的是( )。 class TlestClass { private: int a: public: TestClass(int giva_a=0) {a=give_a;} }
A.~void TestClass (){}
B.~TestClass void(){}
C.void~TestClass(){}
D.~TestClass(){}
第20题:
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;
第21题:
C#中TestClass为一自定义类,其中有以下属性定义: publicvoidProperty{…}开卷考 使用以下语句创建了该类的对象,并使变量obj引用该对象: TestClassobj=newTestClass(); 那么,可通过什么方式访问类TestClass的Property属性?()
第22题:
C#中TestClass为一自定义类,其中有以下属性定义 publicvoidProperty{…} 使用以下语句创建了该类的对象,并使变量obj引用该对象: TestClassobj=newTestClass(); 那么,可通过什么方式访问类TestClass的Property属性?()
第23题:
Obj,Property
MyClass.Property
obj::Property
obj.Property()
第24题:
obj.Hello();
obj::Hello();
MyClass.Hello();
MyClass::Hello();