问题 问答题

下列程序的执行结果是( )。
#include<iostream.h>
class Sample

int x,y;
public:
Sample() x=y=0;
Sample(int a,int b) x=a;y=b;
~Sample()

if(x==y)
cout<<"x=y"<<end1;
else
cout<<"x!=y"<<end1;

void disp()

cout<<"x="<<x<<",y="<<y<<end1;

;
void main()

Sample s1(2,3);
s1.disp();

答案

参考答案:C

解析: 此题考查的是类的构造函数和析构函数。首先,Sample s1(2,3)会调用含有两个参数的构造函数Sample(int a,int b){x=a;y=b;

选择题
填空题