版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、Test Bank for Problem Solving with C+: The Object of Programming, 6/e Chapter 15 InheritanceTRUE/FALSE 1. If you use the keyword virtual in a function declaration, you must also use it in the function definition.ANSWER: FALSE2. Destructors are not inherited into the derived class.ANSWER: TRUE3. The
2、assignment operator is inherited from the base class.ANSWER: FALSE4. The copy constructor from the base class is not inherited into the derived class.ANSWER: TRUE5. All member functions in a base class should be listed as virtual functions.ANSWER: FALSE6. An object of a derived class can be stored i
3、n a base class variableANSWER: TRUE7. The derived class may define variables and member functions other than those that are in the base class.ANSWER: TRUE8. The base class has everything that is in the derived class and moreANSWER: FALSE9. The constructor for a class is inherited.ANSWER: FALSE10. A
4、derived class automatically gets all the member variables from the base class.ANSWER: TRUESHORT ANSWER 1. When we derive one class from another class, this is known as _ANSWER: inheritance2. Which is more general, the base class or the derive class.ANSWER: base class3. The ifstream class is derived
5、from the _ class.ANSWER: istream4. When the derived class gets all the member variables from the base class, we say that they are _ from the base class.ANSWER: inherited5. A constructor of the base class is _ inherited in the derived class (is/is not)ANSWER: is not6. If the member variables in a bas
6、e class are marked as private, can a derived class directly access those variables?ANSWER: No7. If the member variables of the base class are marked as protected, who can access those variables?ANSWER: members, friends, and classes derived from that base class8. Member functions defined as private i
7、n the base class (are/are not) inherited in the derived classANSWER: are not9. If two functions (in the same scope) have the same name, but a different function signature, this means that the functions are _.ANSWER: overloaded10. The ability to associate multiple meanings to one function name using
8、dynamic binding is called _.ANSWER: polymorphism.11. C+ implements polymorphism by waiting until run-time to determine which version of a function to use. This is also known as _.ANSWER: late or dynamic binding12. If a base class has declared a function to be a virtual function, then does the derive
9、d class need to include the word virtual also?ANSWER: No13. A base class pointer variable can point toANSWER: base class and derived class objects14. A derived class pointer can point to ANSWER: derived class objects.15. Using virtual functions is also known as _ the functionsANSWER: overridingMULTI
10、PLE CHOICE1. What is another name for a child class?a. derived classb. sub classc. descendent classd. all of the abovee. none of the aboveANSWER :D2. A base class may have at most _ child class derived from it.a. 1b. 2c. 12d. any number ANSWER :D3. Which is the correct way to tell the compiler that
11、the class being declared (ChildClass) is derived from the base class (BaseClass)?a. class ChildClass:public BaseClassb. class ChildClass:public BaseClassc. class ChildClass childOf public BaseClassd. class ChildClass derived BaseClassANSWER :B4. Another name for the base class isa. parent classb. su
12、per classc. ancestor classd. all of the abovee. none of the aboveANSWER :D5. If you define a function in the derived class that has the same function signature as a function in the base class, this is known asa. overloadingb. redefinitionc. overwritingd. a syntax errorANSWER :B6. If the member varia
13、bles in a base class are private, thena. they can be directly accessed or changed in the derived classb. the derived class must use any accesssor or modifier functions from the base classc. making them private causes a syntax error.d. you must declare them in the derived class also.ANSWER :B7. In th
14、e derived class definition, you list from the base classa. all the member functions every timeb. only those member functions that need to be redefinedc. only those member functions that were in the public sectiond. only those member functions you want to overload.ANSWER :B8. Give a base class with a
15、t least one public member function, how many classes can redefine that member function?a. 1b. 0c. all of themd. none of the aboveANSWER :C9. If a base class has a public member function, and the derived class has a member function with the same name, but with a different parameter list, this functio
16、n is said to bea. overloadedb. redefinedc. overwrittend. a syntax errorANSWER :A10. Using inheritance allows us toa. eliminate duplicate codeb. make our classes more modularc. use polymorphismd. all of the abovee. none of the aboveANSWER :D11. Which of the following are not truea. an object of the d
17、erived class may be stored in a variable of the base classb. an object of the base class may be stored in a variable of the derived classc. an object of a derived class that is derived from another class that is derived from a third class can be stored in a variable of the third class.d. all of the
18、abovee. none of the aboveANSWER :B12. Which of the following are true?a. constructors of the base class are inherited in the derived class.b. you may not call the base constructor from the derived classc. You must define constructors in both the base and derived classesd. all of the abovee. none of
19、the aboveANSWER :E13. If you have the following class definitions, which of the following is the proper way to construct an object of the derived class?class Petpublic: Pet(); void printPet(); string getName(); void setName(string newName);private: string name;class Dog:public Petpublic: Dog(); void
20、 printPet(); void setType(string newType); string getType();private: string type;a. Dog:Dog():Pet(),type("MUTT")b. Dog:Dog()name="Rover"c. Pet:Dog():Pet(),type("MUTT")d. Dog:Pet():Pet(),type("MUTT")ANSWER :A14. If the member variables in the base class are lis
21、ted as protected, then who can access or modify those variables?a. friends of the base classb. friends of the derived classc. members of the base classd. members of the derived classe. A and Bf. C and Dg. All of the aboveANSWER :G15. If a base class has public member functions that are not listed by
22、 a derived class, then these functionsa. are not available to the derived classb. are inherited unchanged in the derived classc. are private to the derived classd. do not exist in the derived classANSWER :B16. When deriving a class, you shoulda. list only base class functions that will be redefinedb
23、. list all the member functions of the base classc. make every function a virtual functiond. overload all the base class member functionsANSWER :A17. If a derived class (Class2) has redefined a function from the base class (Class 1), how can that derived function call the base class function if the
24、function declaration is as follows?void print( );a. :public Class1:print( );b. Class1 : print( );c. print( );d. all of the above.ANSWER :B18. If you have a copy constructor in the base class, but do not have a copy constructor for the derived class, thena. you will have a syntax errorb. a copy const
25、ructor for the derived class is automatically created for youc. you can not use pointer variablesd. the default constructor is usedANSWER :B19. Which of the following would correctly call the base class (BaseClass) assignment operator from the derived class (DerivedClass) assignment operator?Derived
26、Class& DerivedClass:operator =(const DerivedClass& rightSide)/what goes here?a. BaseClass:operator=(rightSide);b. leftSide=rightSide;c. rightSide=BaseClass.rightSide;d. DerivedClass:rightSide=BaseClass:rightSide;ANSWER :A20. Given a class A that derives from a class B that derives from a cla
27、ss C, when an object of class A goes out of scope, in which order are the destructors called?a. C, B, then Ab. A, B, then Cc. unable to determined. depends on how the code is written for the destructorsANSWER :A21. Polymorphism refers toa. the ability to assign multiple meanings to one function name
28、.b. overriding base class functions.c. overloading functionsd. none of the aboveANSWER :A22. In order to tell the compiler to wait to decide which version of a function to use, you must precede the function declaration in the base class with the keyword a. operatorb. friendc. virtuald. voidANSWER :C
29、23. If the following function is in a base class, which of the following are polymorphic declarations of the same function in the derived class?virtual void print( ostream& out);a. virtual void print ( ostream& out);b. void print( ostream& out);c. void print();d. virtual void print();e.
30、A and Bf. A and DANSWER :E24. Given the following simplified classes, class Petpublic: virtual void print(); string name;private:;class Dog: public Petpublic: void print(); string breed;Dog vDog;Pet vPet;vD="rover" vDog.breed = "Collie"Which of the following statements are
31、 not legal?a. vPet=vDog; cout << vD;b. vPet=vDog; cout << vDog.breed;c. vPet=vDog; cout << vP;d. vPet=vDog; cout << vPet.breed;ANSWER :D25. Given the following classes and code, what is the output of the last statement shown?class Petpublic: virtual void print()
32、; string name;private:;class Dog: public Petpublic: void print(); string breed;void Pet:print() cout << "My name is " << name;void Dog:print() Pet:print(); cout << ", and my breed is a "<< breed << endl;Pet* pPtr;Dog* dPtr=new Dog;dPtr->name= &quo
33、t;Rover"dPtr->breed="Weiner"pPtr= dPtr;pPtr->print();a. My name is Rover, and my breed is a Weinerb. My name is Roverc. , and my breed is a Weinerd. nothingANSWER :A26. Given the following classes and code, what is the output of the last statement shown?class Petpublic: virtual
34、void print(); string name;private:;class Dog: public Petpublic: void print(); string breed;void Pet:print() cout << "My name is " << name;void Dog:print() Pet:print(); cout << ", and my breed is a "<< breed << endl;Pet pPtr;Dog dPtr;dPtr->name= "Rover"dPtr->breed="Weiner"pPtr= dPtr;pPtr->print();a. My name is Rover, and my breed is a Weinerb. My name is Ro
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 护理创新技术前沿探索
- 护理机理与护理实施
- 2025-2026学年人教版高一数学下册期末模拟试卷(含参考答案解析)
- 2026启示类面试题型及答案
- 2026区域热点运营面试题及答案
- 2026宿管面试题目及答案
- 2026特岗招聘面试题目及答案
- 麻醉专科护士医院招聘考试参考题库 含答案
- 2026卫校面试题库及答案
- 衔接英语写作衔接词补强|补齐逻辑连接断层
- 第3章物质构成的奥秘章末复习课件-九年级化学沪教版(2024)上册
- 1 十五从军征(说课稿) 统编版 语文九年级下册
- 办证服务合同协议书范本
- DB33-T1027-2018蒸压加气混凝土砌块应用技术规程
- 四川省成都市第十一中学2024-2025学年高一上学期入学分班质量检测数学试题(解析版)
- 8下-02-运动和力(原卷版)-全国初中物理竞赛试题编选
- SH∕T 3097-2017 石油化工静电接地设计规范
- JTS-T-278-1-2019疏浚工程预算定额
- 四年级下册递等式计算300题及答案
- 发运部门管理制度
- 北京外国语大学611英语基础测试(技能)历年考研真题及详解
评论
0/150
提交评论