举一反三
- 阅读以下程序,写出运行结果。 #include using namespace std; class Test { private: int num; public: Test(); Test(int n); }; Test::Test() { cout << "Init defa" << endl; num = 0; } Test::Test(int n) { cout << "Init" << " " << n << endl; num = n; } int main() { Test x[2]; Test y(15); return 0; }
- 有以下类定义:class graphic{private:int n;char ch;public:graphic(int a,char c);void show( );};在main函数中定义一个对象graphic A(5,’*’);调用函数show程序输出为:* * * * ** * * ** * ** **定义一个对象graphic A(3,’#’);调用函数show程序输出为:# # ## ## 请写出相应程序实现之。
- 以下程序的输出结果是 。 #include<iostream> using namespace std; int main() { int num = 50; int& ref = num; ref = ref + 10; cout <<"num = "<<num<<endl; num = num + 40; cout <<"ref = "<<ref<<endl; return 0; }
- 编译运行如下Java代码,输出结果是。 public class Test{ public static void main(String[] args){ int num=5; if(num<=5){ num+=2; System.out.println(num); } System.out.println(num+5); } }
- 在下列类族声明的代码中,正确的访问类N的成员a的语句为 。 class N { public: int a; void display(){cout<<″A::a=”<<a<<endl;} }; class A:public N { public: int a1; }; class B:public N { public: int a2; }; class C :public A,public B { public : int a3; void show{cout<<″a3=″<<a3<<endl;} }; int main { C c1;//定义C类对象c1 ┆ }
内容
- 0
下列程序的输出结果是 _____ 。 #include using namespace std; class Test { public: Test() { cnt++; } ~Test() {cnt--; } static int Count() { returncnt;} private: static int cnt; }; int Test::cnt = 0; int main() { cout << Test::Count()<<' '; Test tl, t2; Test* pT3 = new Test; Test* pT4 = new Test; cout << Test::Count()<<' '; delete pT4; delete pT3; cout << Test::Count()<< endl; return 0; }
- 1
有如下类声明: class Pam{ int k; public: Pam(int n):k(n){} void show()const; };若要在类体外给出成员函数show的定义,下列定义中正确的是 A: voidshow()const{cout<B.voidshow()const{cout<C.voidPam::show()const{cout<D.voidPam::show()const{cout<
- 2
如下代码定义了一个类Test: class Test { private int y; Test (int x) { y:x; } }现在为Test 类生成一个对象,正确的语句是( )。 A: Test t = new Test( ); B: Test t=new Test(10, 20); C: Test t; D: Test t=new Test(10);
- 3
关于属性的使用正确的是? private int num;public string Num{get{return num;};set{num=value;}}|private int num;private int Num{get{return num;}set{num=value;}}|private int num;public int Num{get{return num;}set{num=value;}}|private int num;public int Num{get{num=value;}set{return num;}}
- 4
关于属性的使用正确的是 A: private int num;public string Num{get{return num;} set{num=value;}} B: private int num;public int Num{get{return num;}set{num=value;}} C: private int num;public int Num{get{num=value;}set{return num;}} D: private int num;private int Num{get{return num;}set{num=value;}}