CH11 CSCI

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

Classes can create new classes from existing classes. This important feature ____. a. encourages code reuse b. results in more software complexity c. provides public access to the internal state of an object d. aids the separation of data and operations

a

Consider the following class definitions. class bClass { public: void setX(int a); //Postcondition: x = a; void print() const; private: int x; }; class dClass: public bClass { public: void setXY(int a, int b); //Postcondition: x = a; y = b; void print() const; private: int y; }; Which of the following correctly sets the values of x and y? a. void dClass::setXY(int a, int b) { bClass::setX(a); y = b; } b. void dClass::setXY(int a, int b) { x = a; y = b; } c. void dClass::setXY(int a, int b) { x = bClass::setX(a); y = bClass::setY(b); } d. void dClass::setXY(int a, int b) { x = bClass.setX(a); b = y; }

a

If the derived class classD overrides a public member function functionName of the base class classB, then to specify a call to that public member function of the base class you use the statement ____. a. classB::functionName(); b. classB.functionName(); c. classD::functionName(); d. classD.functionName();

a

Inheritance is an example of what type of relationship? a. is-a b. has-a c. was-a d. had-a

a

The ____ members of an object form its internal state. a. private b. protected c. public d. static

a

The new classes that we create from existing classes are called ____ classes. a. derived b. sibling c. base d. parent

a

To ____ a public member function of a base class in the derived class, the corresponding function in the derived class must have the same name, number, and types of parameters. a. redefine b. overload c. rename d. reuse

a

To ____ a public member function of a base class in the derived class, the corresponding function in the derived class must have the same name, number, and types of parameters. a. redefine b. overload c. rename d. reuse

a

Which of the following statements about inheritance is true if memberAccessSpecifier is protected? a. The public members of the base class become protected members of the derived class. b. The private members of the base class become protected members of the derived class. c. The derived class can directly access any member of the base class. d. The protected members of the base class become private members of the derived class.

a

____ is an "is-a" relationship. a. Inheritance b. Encapsulation c. Composition d. Polymorphism

a

____ is the ability to use the same expression to denote different operations. a. Polymorphism b. Inheritance c. Composition d. Encapsulation

a

C++ provides ____ functions as a means to implement polymorphism in an inheritance hierarchy, which allows the run-time selection of appropriate member functions. a. overridden b. virtual c. redefined d. overloaded

b

Consider the following class definition. class dClass: bClass { //class members list }; The class dClass is derived from the class bClass using the ____ type of inheritance. a. public b. private c. protected d. static

b

Consider the following class definitions: class bClass { public: void setX(int); void print() const; private: int x; }; class dClass: public bClass { public: void setXY(int, int); void print() const; private: int y; }; Which of the following statements correctly redefines the member function print of bClass? a. void dClass::print() const { cout << x << " " << y << endl; } b. void dClass::print() const { bClass::print(); cout << "y = " << y << endl; } c. void bClass::print() const { cout << x << " " << y << endl; } d. void dClass::print() const { dClass:print(); cout << " " << y << endl; }

b

Existing classes, from which you create new classes, are called ____ classes. a. child b. base c. sibling d. derived

b

If the derived class classD overrides a public member function functionName of the base class classB, then to specify a call to that public member function of the base class you use the ____ statement. a. classD::functionName(); b. classB::functionName(); c. classD.functionName(); d. classB.functionName();

b

Suppose that bClass is a class. Which of the following statements correctly derives the class dClass from bClass? a. class dClass:: public bClass { //classMembersList }; b. class dClass: private bClass { //classMembersList }; c. class dClass:: protected bClass { //classMembersList }; d. class bClass: public dClass { //classMembersList };

b

The ____ members of an object form its external state. a. private b. public c. protected d. static

b

What is the output of the following program? #include <iostream> using namespace std; class bClass { public: void print() const; bClass(int a = 0, int b = 0); //Postcondition: x = a; y = b; private: int x; int y; }; class dClass: public bClass { public: void print() const; dClass(int a = 0, int b = 0, int c = 0); //Postcondition: x = a; y = b; z = c; private: int z; }; int main() { bClass bObject(2, 3); dClass dObject(3, 5, 8); bObject.print(); cout << endl; dObject.print(); cout << endl; return 0 ; } void bClass::print() const { cout << x << " " << y << endl; } bClass::bClass(int a, int b) { x = a; y = b; } void dClass::print() const { bClass:print(); cout << " " << z << endl; } dClass::dClass(int a, int b, int c) : bClass(a, b) { z = c; } a. 2 3 2 3 b. 2 3 3 5 8 c. 3 5 8 3 5 8 d. 5 8 3 5 8

b

Which of the following class definitions makes the public members of the class aClass become the public members of the class bClass? a. class bClass: aClass { //... }; b. class bClass: public aClass { //... }; c. class aClass: public bClass { //... }; d. class aClass: bClass { //... };

b

Which of the following class definitions makes the public members of the class aClass become the public members of the class bClass? a. class aClass: public bClass { //... }; b. class bClass: public aClass { //... }; c. class bClass: aClass { // }; d. class aClass: bClass { //... };

b

Which of the following is a valid definition of the derived class bClass? a. class aClass: public bClass { // ... }; b. class bClass: public aClass { // ... }; c. class aClass::bClass { // ... }; d. class bClass::aClass { // ... }

b

Which of the following is true about a derived class? a. A derived class can directly access any member variable of the base class. b. A derived class can redefine any public member function of the base class. c. A derived class can have at most one base class. d. A derived class can redefine any member function of the base class.

b

____ is the ability to combine data, and operations on that data, in a single unit. a. Inheritance b. Encapsulation c. Polymorphism d. Composition

b

C++ provides ____ functions as a means to implement polymorphism in an inheritance hierarchy, which allows the run-time selection of appropriate member functions. a. redefined b. overridden c. virtual d. overloaded

c

If the corresponding functions in the base class and the derived class have the same name but different sets of parameters, then this function is ____ in the derived class. a. reused b. redefined c. overloaded d. overridden

c

Which of the following statements about inheritance is true if memberAccessSpecifier is protected? a. The private members of the base class become protected members of the derived class. b. The derived class can directly access any member of the base class. c. The public members of the base class become protected members of the derived class. d. The protected members of the base class become private members of the derived class.

c

____ is a "has-a" relationship. a. Inheritance b. Encapsulation c. Composition d. Polymorphism

c

____ is the ability to use the same expression to denote different operations. a. Inheritance b. Encapsulation c. Polymorphism d. Composition

c

Consider the following class definitions. class bClass { public: void set(double a, double b); //Postcondition: x = a; y = b; void print() const; bClass(); //Postcondition: x = 0; y = 0; bClass(double a, double b); //Postcondition: x = a; y = b; private: double x; double y; }; class dClass: public bClass { public: void set(double a, double b, double c); //Postcondition: x = a; y = b; z = c; void print() const; dClass(); //Postcondition: x = 0; y = 0;z = 0 ; dClass(double a, double b, double c); //Postcondition: x = a; y = b; z = c; private: double z; }; Which of the following dClass constructor definitions is valid in C++? a. dClass::dClass(double a, double b, double c) : bClass() { x = a; y = b; z = c; } b. dClass::dClass(double a, double c) { x = a; z = c; } c. dClass::dClass(double a, double b) : bClass() { x = a; y = b; } d. dClass::dClass(double a, double b, double c) : bClass(a, b) { z = c; }

d

If the corresponding functions in the base class and the derived class have the same name but different sets of parameters, then this function is ____ in the derived class. a. overridden b. reused c. redefined d. overloaded

d

OOP implements ____. a. UML b. IPE c. EIP d. OOD

d

The ____ members of an object form its internal state. a. static b. protected c. public d. private

d

Which of the following is true about inheritance? a. All public member functions of the base class become the public member functions of the derived class. b. All public member variables of the base class become the public member variables of the derived class. c. All public members of the base class become the public members of the derived class. d. The public member variables of the base class become the public or private member variables of the derived class.

d

(T/F) A derived class cannot directly access public members of a base class.

false

(T/F) If inheritance is private , all members of the base class, including private members, become private members of the derived class.

false

(T/F) If inheritance is private, all members of the base class, including private members, become private members of the derived class.

false

(T/F) The class io is the base class of the C++ stream classes istream and ostream .

false

(T/F) The private members of a base class can be directly accessed by a derived class.

false

(T/F) A call to the base class's constructor is specified in the heading of the definition of a derived class constructor.

true

(T/F) A derived class can directly access the protected members of the base class.

true

(T/F) If the derived class does not override a public member function of the base class, you may specify a call to that public member function by using the name of the function and the appropriate parameter list.

true

(T/F) In multiple inheritance, the derived class has more than one base class.

true

(T/F) In protected inheritance, public and protected members of the base class become the protected members of the derived class.

true

(T/F) The constructors of a derived class can (directly) initialize only the ( public data) members inherited from the base class of the derived class.

true

(T/F) The constructors of a derived class can (directly) initialize only the (public data) members inherited from the base class of the derived class.

true


Set pelajaran terkait

Peripheral Venous Disease med surg questions

View Set

Using the First Derivative Test to Find Relative (Local) Extrema Quiz (MCQs)

View Set

Anatomy chapter 4 Review, Chapter 4 Anatomy

View Set

Prep U Quiz 3 ch 24 Asepsis and Infection Control

View Set