阅读以下程序,写出运行结果。
#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;
}
#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;
}
举一反三
- 下列程序的输出结果是 _____ 。 #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; }
- 一个类的定义如下,在主程序中定义对象t,且使对象t的num=20,并使用show()函数输出这个对象的值。#include using namespace std;class Test{private:int num;public: Test(int n){ num=n; }void show() { cout<
- 有如下程序:#includeusing namespace std;Class Testpublic:Test()Test(const Test&t)cout<<1;);Test fun(Test &u)Test t=u;retum t;int main()Test X,y;x=fun(y);retum 0;运行这个程序的输出结果是()。 A: 无输出 B: 1 C: 11 D: 111
- 已有如下程序: public class Test{ public Test(int x,int y,int z){.....} } 下面哪些方法是合法的构造方法重载:( ) A: Test(){} B: int Test(){} C: Test(int x,int y,byte z){} D: void Test(int x,int y,int z){}
- (6-6)请阅读程序,写出程序运行结果。 class Test{ static int x=10; int y=99; { y=y+10; } static { x=x+5; } { y=y+10; } static { x=x+5; } public Test() {//构造方法 x=x+5; } { System.out.println(x*y); } } public class Demo11 { public static void main(String[] args) { Test t1=new Test(); Test t2=new Test(); } }