下面是类Cls的定义。对定义中语句描述正确的是______。
classCls
{
public:
voidCls(intx1)//(1)
{
x=x1;
}
intf(intx1,inty1)//(2)
{
x=x1;
y=y1;
}
intf(intx1,inty1,intz1=0)//(3)
{
x=x1;
y=y1;
z=z1;
}
voidChan()//(4)
{
y+=20;
}
private:
intx,y,z;
};
classCls
{
public:
voidCls(intx1)//(1)
{
x=x1;
}
intf(intx1,inty1)//(2)
{
x=x1;
y=y1;
}
intf(intx1,inty1,intz1=0)//(3)
{
x=x1;
y=y1;
z=z1;
}
voidChan()//(4)
{
y+=20;
}
private:
intx,y,z;
};
举一反三
- 有基类如下:classBASE{private:intx,y;public:BASE(intx,inty){this->x=x;this->y=y;}voidset(intx1,inty1){x=x1;y=y1;}...};设DERIV为BASE的公有派生类,则下列哪个DERIV的构造函数对基类成员的初始化是正确的? A: DERIV(int x,inty){BASE(x,y);...} B: DERIV(intx1,inty1){x=x1;y=y1;...} C: DERIV(intx,inty):BASE(x,y){...} D: DERIV(intx,inty){set(x1,y1);...}
- intx=5,y=8,z=7;表达式z=!(x>y)||(x=1,y=3)计算后的结果 A: x=1,y=3,z=1 B: x=1,y=3,z=0 C: x=5,y=8,z=0 D: x=5,y=8,z=1
- main(){intx=0,z,y=z=-1;x=x---z-y;printf("x=%d\n",x);}输出结果是:main(){intx=0,z,y=z=-1;x=--x-z-y;printf("x=%d\n",x);}输出结果是:1
- intx=1,y=2,z=3;以下语句执行后x,y,z的值是x=-1,y=(),z=10。X=-X;Y++;Z=int(x/Y);printf("x=%d,y=%d,z=%d ",x,y,z);
- 以下各选项中的代码段执行后,变量y的值不为1的是 A: intx=10,y=0;if(x=y)y=1; B: intx=5,y=0;if(x)y=1; C: intx=5,y=0;if(5)y=1; D: intx=5,y=10;if(x=y)y=1;