练习08-多态性
练习08-多态性(2024级)
题量: 20 满分: 100
作答时间:05-10 19:45 至_06-15 19:45_
1.(单选题) 假定为类X成功重载了++、=、-和[]等运算,则其中肯定是成员函数的运算符是( )。
- A. -和=
- B. []和++
- C. =和[]
- D. -和[]
2.(单选题) 在下面的重载运算符函数的原型中,错误的是( )。
- A. FunType operator -(FunType,FunType);
- B. FunType operator -(long,long);
- C. FunType operator -(FunType,long);
- D. FunType operator -(long,FunType);
3.(单选题) 在重载一个运算符时,如果其参数表中有一个参数,则说明该运算符是( )。
- A. 一元成员运算符
- B. 二元成员运算符
- C. 一元友元运算符
- D. B和C都可能
4.(单选题)
有类定义如下,若有对象定义Type c1; 则下列语句序列中,错误的是( )。
class Type
{
int val;
public:
Type( int i=0);
Type operator - ( int );
friend Type operator + ( Type, Type);
};
- B. c1+Type(3);
- C. 3-c1;
- D. c1-3;
5.(单选题) 下列运算符中,在C++语言中不能重载的是( )。
- A. *
- B. >=
- C. ::
- D. /
6.(单选题) 从下列运算符函数的原型看,肯定不属于类FunType的成员函数的是( )。
- A. int operator+(FunType);
- B. FunType operator+( );
- C. FunType operator+( int );
- D. int operator+( FunType, FunType);
7.(单选题) 将前缀运算符“--”重载为非成员函数,下列原型中,能正确用于类中说明的是( )。
- A. Decr& operator --(int);
- B. Decr operator --( Decr&,int);
- C. friend Decr& operator --(Decr&);
- D. frlend Decr operator --(Decr&,int);
8.(单选题) 下列关于运算符重载的描述中,错误的是( )。
- A. 重载类型转换运算符时不需要声明返回类型
- B. 赋值运算符只能重载为成员函数
- C. 运算符函数重载为类的成员函数时,第一操作数是该类对象
- D. 可以通过运算符重载在C++中创建新的运算符
9.(单选题) 若在表达式y/x中,“/”是作为成员函数重载的运算符,则该表达式还可以表示为( )。
- A. x.operator/(y)
- B. operator/(x,y)
- C. y.operator/(x)
- D. operator/(y,x)
10.(单选题) 下列关于赋值运算符“=”重载的叙述中,正确的是( )。
- A. 如果己经定义了复制(拷贝)构造函数,就不能重载赋值运算符
- B. 默认的赋值运算符实现了“深层复制”功能
- C. 重载的赋值运算符函数有两个本类对象作为形参
- D. 赋值运算符只能作为类的成员函数重载
11.(单选题) 若要对类BigNumber中重载的类型转换运算符long进行声明,下列选项中正确的是( )。
- A. operator long() const;
- B. operator long(BigNumber);
- C. long operator long() const;
- D. long operator long(BigNumber);
12.(单选题) 已知将运算符“+”和“”作为类Complete的成员函数重载,设c1和c2是类Complex的对象,则表达式c1+c2c1等价于( )。
- A. c1.operator*(c2.operator+(c1))
- B. c1.operator+(c2.operator*(c1))
- C. c1.operator*(c1.operator+(c2))
- D. c2.operator+(c1.operator*(c1))
13.(单选题) 有如下程序:
#include<iostream>
using namespace std;
class Amount{
int amount;
public:
Amount(int n=0): amount(n){ }
int getAmount()const{ return amount; }
Amount &operator +=(Amount a){
amount+=a.amount;
return( ) ;
}
};
int main(){
Amount x(3),y(7);
x+=y;
cout<<x.getAmount()<<endl;
}
- A. *this
- B. this
- C. &amount
- D. amount
14.(单选题) 下列各种类中,不能定义对象的类是( )。
- A. 派生类
- B. 抽象类
- C. 组合类
- D. 虚基类
15.(单选题) 虚函数必须是类的( )。
- A. 成员函数
- B. 友元函数
- C. 静态函数
- D. 析构函数
16.(单选题) 下列成员函数中,纯虚函数是( )。
- A. virtual void f1() = 0;
- B. void f1() = 0;
- C. virtual void f1() {}
- D. virtual void f1() == 0;
17.(单选题) 下面关于虚函数的描述中正确的是( )。
- A. 虚函数是一个静态成员函数
- B. 虚函数是一个非成员函数
- C. 虚函数可以在函数说明时定义,也可以在函数实现时定义
- D. 派生类的虚函数与基类中对应的虚函数具有相同的参数个数和类型
18.(单选题) 若下面程序运行时输出结果是“文学”,则划线处缺失的语句是( )。
#include<iostream>
using namespace std;
class Book{
public:
Book(char* t=""){ strcpy(titie,t); }
()
private:
char title[40];
};
class Novel:public Book{
public:
Novel(char *t=""):Book(t){ }
char *Category()const { return "文学"; }
};
int main(){
Book *pb;
pb=new Novel();
cout<<pb->Category();
return 0;
}
- B. char Category()const;
- C. virtual char Category() const;
- D. virtual char Category() const=0;
19.(单选题) 如下程序的输出结果是( )。
#include<iostream>
using namespace std;
class Base{
public:
virtual void Show(){ cout<<'B'; }
};
class Derived:public Base{
public:
void Show(){ cout<<'D'; }
};
int main(){
Base *p1=new Derived;
Derived *p2=new Derived;
p1->Show();
p2->Show();
delete p1;
delete p2;
return 0;
}
- B. BD
- C. DB
- D. DD
20.(单选题)
如下程序的输出结果是( )。
#include<iostream>
using namespace std;
class B
{
public:
virtual void f() { cout<<"B"; }
void g(){ cout<<"B"; }
};
class D:public B
{
public:
void f(){ cout<<"D"; }
void g(){ cout<<"D"; }
};
void h(B*p)
{ p->f(); p->g(); }
int main()
{
D obj;
h(&obj);
return 0;
}
- B. BB
- C. BD
- D. DB
练习08-多态性(2024级)答案
正确答案列表:
- C
- B
- D
- C
- C
- D
- C
- D
- C
- D
- A
- B
- A
- B
- A
- A
- D
- D
- D
- D