网友您好, 请在下方输入框内输入要搜索的题目:

题目内容 (请给出正确答案)

2、关于下面程序段说法正确的是() class X { private: int n; public: X(X&); }; X::X(X&x) {n=x.n} X obj1,obj2(obj1);

A.语句obj2(obj1);的功能是用对象obj1初始化具有相同类类型的对象obj2

B.语句obj2(obj1);的功能是用对象obj2初始化具有相同类类型的对象obj1

C.X(X&x)中的&符号可以删除

D.X(X&x)函数中不能访问对象的私有成员


参考答案和解析
该类不能被继承
更多 “2、关于下面程序段说法正确的是() class X { private: int n; public: X(X); }; X::X(Xx) {n=x.n} X obj1,obj2(obj1);A.语句obj2(obj1);的功能是用对象obj1初始化具有相同类类型的对象obj2B.语句obj2(obj1);的功能是用对象obj2初始化具有相同类类型的对象obj1C.X(Xx)中的符号可以删除D.X(Xx)函数中不能访问对象的私有成员” 相关考题
考题 ( 28 )有如下程序:#includeiostreamusing namespace std;class MyClass{public:MyClass(int x):val(x) {}void Print() const {cout"const:val="val'\t';}void Print(){cout"val="val't';}private:int val;};int main(){const MyClass obj1(10);MyClass obj2(20);obj1.Print();obj2.Print();return 0;}程序的输出结果是A ) val=10 const:val=20B ) const:val=10 const:val=20C ) const:val=10 val=20D ) val=10 val=20

考题 ( 30 )有如下程序:#includeiostreamusing namespace std;class AA{lilt k;protected:int n;void setK ( int k ) { this-k=k;}public:void setN ( int n ) { this-n=n;}};class BB: public }{/* 类体略 */};int main () {BB x_ ; //1x .n=1; //2x.setN ( 2 ) ; //3x.k=3; //4x .setK ( 4 ) ;return 0;}在标注号码的四条语句中正确的是A ) 1B ) 2C ) 3D ) 4

考题 有如下类声明: class Base{ protected: int amount; public: Base(int n=0):araount(n){ } int getAmount( )const{retum amount;} }; class Derived:public Base{ protected; int value; public: Derived(int m,int n):value(n1),Base(n){ } int getData( )const{return value+amount;} }; 已知x是一个Derived对象,则下列表达式中正确的是A.x.value+x.getAmount( )B.x.getData( )-x.getAmount( )C.x.getData( )-x.amountD.x.value+x.amount

考题 有如下程序:includeusing namespace std;class Base{int x;public:Base(int n=0):x(n 有如下程序: #include<iostream> using namespace std; class Base{ int x; public: Base(int n=0):x(n){cout<<n;} int getX( )const{return x;} }; class Derived:public Base{ int y; public: Derived(int m,int n):y(m),Base(n){tout<<m;} Derived(int m):y(m){cout<<m;} }; int main( ){ Derived dl(3),d2(5,7); return 0; } 程序的输出结果是A.375B.357C.0375D.0357

考题 关于下面程序段说法正确的是()。class X { private: int n; public: X(X }; X::X(X A.语句obj2(obj1);的功能是用对象obj2初始化具有相同类类型的对象obj1B.语句obj2(obj1);的功能是用对象obj1初始化具有相同类类型的对象obj2C.X(X&x)函数中不能访问对象的私有成员D.X(X&x)中的&符号可以删除

考题 有如下程序 public class Sun { public static void main(String args[ ]) { int x=0; int n=0; while(x50) { x=(x+2)*(x+3); n=n+1; } System.out.println(n+"和"+x); } } 上述程序的运行结果是( )。A.1和0B.2和72C.3和50D.4和168

考题 有以下程序:includeusing namespace std;classA{private: int x;public: A(int a) {x 有以下程序: #include<iostream> using namespace std; class A { private: int x; public: A(int a) { x=a; } friend class B; }; class B { public: void print(A a) { a.x--; cout<<a, x<<end1; } }; int main () { A a(10); B b; b.print (a) ; return 0; } 程序执行后的输出结果是( )。A.9B.10C.11D.12

考题 有如下程序:#includeiostreamusing namespace std;class AA{int k:protected:int n;void setK(int k){mis-k=k;}.public:void setN(int n){tllis-n=n;}};class BB:public AA{/*类体略*/};int main(){BB X;x.n=l: //1x.setN(2); //2x.k=3: ///3X.setK(4); //4return 0;}在标注号码的4条语句中正确的是A.1B.2C.3D.4

考题 有如下类的声明: class Base{ protected: int amount; public: Base(int n=0):amount(n){} int getAmount()const{return amount;} }; class Derived:public Base{ protected: int value public: Derived(int m,int n):value(m),Base(n){} int getData()const{return value+amount;} };已知x是一个Derived对象,则下列表达式中正确的是A.x. value+x. getAmount()B.x. getData()-x. getAmount()C.x. getData()-x. amountD.x. value+x. amount

考题 有如下程序: include using namespace std; class Base{ int x; pu 有如下程序: #include<iostream> using namespace std; class Base{ int x; public: Base(int n=0):x(n){cout<<n;) int getX()const{return x;} }; class Derived:public Base{ int y; public: Derived(int m,int n):y(m,)Base(n){cout<<m;} Derived(int m):y(m){cout<<m;} }; int main(){ Derived d1(3),d2(5,7) return 0; }运行时的输出结果是A.375B.357C.375D.357

考题 有如下类声明: class Base{ protected: int amount; public: Base(int n=0):amount(n){} int getAmountconst{retum amount;} }; class Derived:public Base{ protected: int value; public: Derived(int m,int n):value(m),Base(n){} int getDataconst{return value+amount;} }: 已知x是一个Derived对象,则下列表达式中正确的是( )。A.x.value+X.getAmountB.x.getData一x.getAmountC.x.getData一x.amountD.x.value+X.amount

考题 若有以下程序:includeusing namespace std;class data{public: int x; data(int x){ 若有以下程序: #include<iostream> using namespace std; class data { public: int x; data(int x) { data::x=x; } class A private: data dl; public: A(int x): dl(x){ } void dispaO cout<<dl.x<<","; } }; class B: public A { private: data d2; public: B(int x):A(x-1),d2(x){ } void dispb() { cout<<d2.x<<endl; } }; class C: public B { public: C(int x):B(x-1){ } void disp0 { dispa(); dispb(); } }; int main() { C obj(5); obj.disp(); return 0; } 程序执行后的输出结果是( )。A.5,5B.4,5C.3,4D.4,3

考题 若有以下程序:include using namespace std;class data{public: int x; data (int x) 若有以下程序: #include <iostream> using namespace std; class data { public: int x; data (int x) { data: :x=x; } }; class A { private: data d1; public: A(int x) : d1 (x) { } void dispa() { cout<<d1, x<<", "; } }; class B: public A { private: data d2; public: B(int x) : A(x-1),d2(x) {} void dispb() { cout<<d2.x<<end1; } }; class C : public B { public: C(int x) : B(x-1){} void disp () { dispa ( ); dispb (); } }; int main ( ) { C obj (5); obj.disp(); return 0; } 程序执行后的输出结果是( )。A.5,5B.4,5C.3,4D.4,3

考题 有如下程序: include class x { protected: int a; public:x(){ a=1;} }; class x 有如下程序: #include <iostream.h> class x { protected: int a; public: x() { a=1; } }; class x1 : virtual public x { public: x1() { a+=1; cout<<a; } }; class x2 : virtual public x { public: x2() { a+=2; cout<<a; } }; class y : public xl,public x2 { public: y() { cout<<a<<end1; } }; int main() { y obj; return O; } 该程序运行后的输出结果是( )。A.1B.123C.242D.244

考题 若有以下程序:includeusing namespace std;class A{private:int a; public:void seta 若有以下程序: #include<iostream> using namespace std; class A { private: int a; public: void seta(int x) { a=x; } void showa() { cout<<a<<","; } }; class B { private: int b; public: void setb(int x) { b=x; } void showb() { cout<<b<<",”; } }; class C:pUblic A,private B { private: int c; public: void setc(int x,int y,int z) { c=z; seta(x); setb(y); } void showc() { showa(); showb(); cout<<c<<end1; } }; int main() { Cc; c.setc(1,2,3); c.showc(); retrun 0; } 程序执行后的输出结果是A.1,2,3B.1,1,1C.2,2,2D.3,3,3

考题 下面程序中错误之处是 ______。 include classA{private:intxl;protected:intx2;publ 下面程序中错误之处是 ______。include<iostream.h>class A{private:int xl;protected:int x2;public:int x3;};class B: public A{private:int b1;protected:int b2;public:int b3;void disp(){cout<<x1<<b2<<end1;} //Avoid set(int i){x3=i;} //B};void main()B bb;bb. a3=10 //Cbb. b3=10 //D}

考题 若有以下程序:includeusing namespace std;class A{private:inta;public:voidseta(in 若有以下程序: #include <iostream> using namespace std; class A { private: int a; public: void seta(int x) { a=x; } void showa() { cout<<a<<","; } }; class B { private: int b; public: void setb (int x) { b=x; } void showb() { cout<<b<<","; } }; class C :public A,private B { private: int c; public: void setc(int x, inc y, int z) { c=z; seta (x); setb (y); } void showc() { showa (); showb (); cout<<c<<end1; } }; int main () { C c; c. setc(1,2,3); c.showc(); return 0; } 程序执行后的输出结果是A.1,2,3B.1,1,1C.2,2,2D.3,3,3

考题 若有以下程序:include using namespaces std;class A{public: A (){} A (int i) {x1= 若有以下程序: #include <iostream> using namespaces std; class A { public: A (){} A (int i) { x1=i; } void dispa() { cout<<"xl="<<xl<<" , "; } private: int x1; }; class B : public A { public: B (){} B (int i):A(i+10) { x2=i; } void dispb() { dispa (); cout <<"x2="<<x2<<end1; } private: int x2; }; int main () { B b(2); b.dispb (): return 0; } 程序运行后的输出结果是( )。A.x1=10,x2=2B.x1=12,x2=10C.x1=12,x2=2D.x1=2,x2=2

考题 若有以下程序:include using namespace std;class A{private:int a;public:void seta 若有以下程序:#include <iostream>using namespace std;class A{private: int a;public: void seta(int x) { a=x; } void showa() { cout<<a<<","; }};class B{private: int b;public: void setb(int x) { b=x; } void showb() { cout<<b<<","; }};class C: public A, private B{private: int c;public: void setc(int x, int y, int z) { c=z; seta(x); setb(y); } void showc() { showa(); showb(); cout<<c<<end1; }};int main(){ C c; c.setc(1,2,3); c.showc(); return 0;}程序执行后的输出结果是( )。A.1,2,3B.1,1,1C.2,2,2D.3,3,3

考题 已知类X的定义如下,为了实现将对象成员k的值修改为678,下面的哪条语句是正确的 ______。 class X{ private: int k; public: K(int n){k=n;} set(int n){k=m;} }; void fun(){ X a(10),*p=a; ______ }A.p->set(678);B.X(678):C.p->k=678;D.p.set(678);

考题 若有以下程序:include using namespace std;class datapublic:int x;data(int x) { d 若有以下程序: #include <iostream> using namespace std; class data public: int x; data(int x) { data: :x=x; }; class A private: data d1; public: A(int x): d1(x){} void dispa() { cout<<d1.x<<","; } }; class B: public A { private: data d2; public: B(int x): A(x-1),d2(x){} void dispb() { cout<<d2.x<<end1; } }; class C: public B { public: C(int x): B(x-1){} void disp() { dispa(); dispb(); } }; int main() { C obj(5); obj.disp(); return 0; 程序执行后的输出结果是 }A.5,5B.4,5C.3,4D.4,3

考题 若有以下程序:includeusing namespaces std;class A{public:A(){}A(int i){x1=i; } v 若有以下程序: #include<iOStream> using namespaces std; class A { public: A(){} A(int i) { x1=i; } void dispa() { cout<<"X1="<<x1<<",": } private; int x1; }; class B:public A { public: B(){} B(int i):A(i+10) { x2=i; } void dispb() { dispa(); cout<<"x2="<<x2<<end1; } private: int x2; }; . int main() { B b(2); b.dispb() return 0; } 程序运行后的输出结果是( )。A.x1=10,x2=2B.x1=12,x2=10C.x1=12,x2=2D.x1=2,x2=2

考题 若有以下程序:includeusing namespace std;class data{public:int x;data(int x){ da 若有以下程序: #include<iostream> using namespace std; class data { public: int x; data(int x) { data::x=x; } }; class A { private: data d1; public: A(int x):d1(x){} void dispa() { cout<<d1.X<<","; } }; classB:public A { private: data d2; public: B(int x):A(x-1),d2(x){} void dispb() { cout<<d2.x<<end1; } }; class C:public B { public: C(int x):B(x-1){} void disp() { dispa(); dispb(); } }; int main() { C obj(5); obj.disp(); return 0; } 程序执行后的输出结果是A.5,5B.4,5C.3,4D.4,3

考题 在下列源代码文件Test.java中,哪个选项是正确的类定义? ( )A.public class test { public int x=0; public test(int x) { this.x=x; } }B.public class Test { public int x=0; public Test(int x) { this.x=x; } }C.public class Test extends Ti,T2 { public int x=0; public Test(int x) { this.x=x; } }D.protected class Test extends T2 { public int x=0; public Test(int x) { this.x=x; } }

考题 有以下程序includeusing namespace std;class MyClass{public:MyClass(int n){number 有以下程序 #include<iostream> using namespace std; class MyClass { public: MyClass(int n){number =n; } //拷贝构造函数 MyClass(MyClass other) {number=other.number;} ~MyClass() {} private: int number; }; MyClass fun(MyClass p) { MyClass temp(p); return temp; } int main() { MyClass Obj1(10),obj2(0); MyClass obj3(obj1); obj2=fun(obj3); return 0; } 程序执行时,MyClass类的拷贝构造函数被调用的次数是A.5B.4C.3D.2

考题 下列程序编译错误,是由于划线处缺少某个语句,该语句是______。 include class A { pr 下列程序编译错误,是由于划线处缺少某个语句,该语句是______。include<iostream.h>class A{private:int numl;public:A( ):numl(0){}A(int i):numl(i){}};class B{private:int num2;public:B( ):num2(0){}B(int i):num2(i){}int my_math(A obj1, B obj2);};int B::my_math(A obj1,B obj2){return(obj1.numl+obj2.num2);}void main(void){A objl(4);B obj,obj2(5);cout<<"obj1+obj2:"<<obj.my_math(obj1,obj2);}

考题 下列程序的输出结果是______。 include using namespace std; class base { public: in 下列程序的输出结果是______。include<iostream>using namespace std;class base{public:int n;base(int x){n=x;}virtual void set(int m){n=m;cout<<n<<'';}};class deriveA:public base{public:deriveA(int x):base(x){}void set(int m){n+=m;cout<<n<<'';}};class deriveB:public base{public:deriveB(int x):base(x){}void set(int m){n+=m;cout<<n<<'';}};int main( ){deriveA d1(1);deriveB.d2(3);base*pbase;pbase=d1;pbase->set(1);pbase=d2;pbase->set(2);return 0;}

考题 对于下面定义的类MyClass,请在函数f( )中添加对象成员把n的值修改为50。class MyClass{public:MyClass(int x){n=x;}void SetNum(int n1){n=n1;}private:int n;};void f(){My Class*ptr=new MyClass(45);【12】}