Final C++ - Chapter 11: Object-Oriented Programming: Inheritance

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

Which of the following is not one of the disadvantages of using the "copy-and-paste" approach to duplicating code from one class into another class? a. Errors are prone to be spread around. b. It is time consuming. c. It forces the system to store many physical copies of the code, creating a code-maintenance nightmare. d. All of the above are disadvantages of the "copy-and-paste" approach.

All of the above are disadvantages of the "copy-and-paste" approach

Assuming the following is the beginning of the constructor definition for class BasePlus-CommissionEmployee which inherits from class Point: BasePlusCommissionEmployee::BasePlusCommissionEmployee(string first, string last, string ssn, double sales, double rate, double salary) : CommissionEmployee(first, last, ssn, sales, rate) The line beginning with a colon(:) a. Invokes the CommissionEmployee constructor with arguments. b. Causes a compiler error. c. Is unnecessary because the CommissionEmployee constructor is called automatically. d. Indicates inheritance.

a. Invokes the CommissionEmployee constructor with arguments

Which of the following is most likely a base class of the other three? a. automobile. b. convertible. c. miniVan. d. sedan

a. automobile.

To declare class subClass a privately derived class of superClass one would write: a. class subclass : private superClass b. class subclass :: private superClass c. class subclass <private superClass> d. class subclass inherits private superClass

a. class subclass : private superClass

Which of the following statements about inheriting base class constructors is false? a. To inherit a base class's constructors, you write the following line of code in the derived class definition (BaseClass is the base class's name): using BaseClass::BaseClass; b. If an inherited base-class constructor has default arguments, the line of code in Part (a) causes the compiler to generate a derived-class constructor with the same default arguments. c. By default, each inherited constructor has the same access level (public, protected or private) as its corresponding base-class constructor. d. If the derived class does not explicitly define constructors, the compiler generates a default constructor in the derived class—even if it inherits other constructors from its base class.

b. If an inherited base-class constructor has default arguments, the line of code in Part (a) causes the compiler to generate a derived-class constructor with the same default arguments.

The is-a relationship represents. a. Composition. b. Inheritance. c. Information Hiding. d. A friend.

b. Inheritance.

From most restrictive to least restrictive, the access modifiers are: a. protected, private, public b. private, protected, public c. private, public, protected d. protected, public, private

b. private, protected, public

Assuming the definition, class BasePlusCommissionEmployee : public CommissionEmployee which of the following is false? a. The colon (:) in the header of the class definition indicates inheritance. b. The keyword public indicates the type of inheritance. c. All the public and protected members of class BasePlusCommissionEmployee are inherited as public and protected members, respectively, into class CommissionEmployee. d. CommissionEmployee is the base class and BasePlusCommissionEmployee is the derived class

c. All the public and protected members of class BasePlusCommissionEmployee are inherited as public and protected members, respectively, into class CommissionEmployee

When should base class members be declared protected? a. When all clients should be able to access these members. b. When these members are used only by member functions of this base class. c. When these members should be available only to derived classes (and friends), but not to other clients. d. The protected access specified should never be used.

c. When these members should be available only to derived classes (and friends), not to other clients.

When deriving a class from a protected base class, the public members of the base class become _________ and the protected members of the base class become __________? a. protected, private b. public, private c. protected, protected d. public, protected

c. protected, protected

Which of the following is not a kind of inheritance in C++? a. public. b. private. c. static. d. protected.

c. static

Select the false statement regarding inheritance. a. A derived class can contain more attributes and behaviors than its base class. b. A derived class can be the base class for other derived classes. c. Some derived classes can have multiple base classes. d. Base classes are usually more specific than derived classes.

d. Base classes are usually more specific than derived classes.

Which forms of inheritance are is-a relationships? a. All forms of inheritance are is-a relationships. b. Only public and private. c. Only public and protected. d. Only public.

d. Only public.

Which of the following is not a good example of a hierarchy likely to be modeled by inheritance? a. Airplanes. b. Geometric shapes. c. Animals. d. Prime numbers.

d. Prime numbers.

Base class constructors and assignment operators: a. Are not inherited by derived classes. b. Should not be called by derived class constructors and assignment operators. c. Can be inherited by derived classes, but generally are not. d. Can call derived-class constructors and assignment operators.

a. Are not inherited by derived classes.

When an object of a derived class is instantiated, the __________ constructor initializes the _________ members. a. Base class, base class. b. Derived class, base class. c. Base class, derived class. d. Derived class, public.

a. Base class, base class.

protected base class members cannot be accessed by: a. Functions that are neither friends of the base class, derived-class member functions nor friends of a derived class. b. friends of the base class. c. Functions that are not derived-class member functions. d. friends of derived classes.

a. Functions that are neither friends of the base class, derived-class member functions nor friends of a derived class.


Kaugnay na mga set ng pag-aaral

Social Studies Quiz - Chapter 20

View Set

Universal Law of Gravitation / Assignment

View Set

HW 4: CH 25 History of Life on Earth

View Set

Battle of the Atlantic Video Study Guide

View Set

EMT chap 30: Abdominal and Genitourinary Injuries

View Set

Nutrition & Foods Chapter 13 - Grains

View Set