MAC 125/ Exception Handling,Inheritance/Ch 14,18
Consider the class inheritance. class B{ public: B(); B(int nn); void f(); void g(); private: int n; }; class D: public B{ public: D(int nn, double dd); void h(); private: double d; }; How many private members (including constructors) does an object of class D have?
2
Consider the class inheritance. class B{ public: B(); B(int nn); void f(); void g(); private: int n; }; class D: public B{ public: D(int nn, float dd); void h(); private: double d;}; Which of the following functions can be invoked by an object of class D?
void f(); void g(); void h();
Suppose class Child is derived from class Parent was in turn derived from class GrandParent. The class Parent and GrandParent are the
Ancestor classes of class Child
Inheritance does NOT:
better model the real world
Which of the following is correct syntax to declare C++ class B to be a public base class for derived class D
class D : public B {/* ... */};
A programmer must have the source code for libraries to extend them, even using inheritance.
incorrect
A base/member initialization list is preceded by
single colon
A function declared thus: void func(argument list) throw (); should throw no exception of any type
true
A function uses an exception specification that includes only int, but an exception of type double is thrown. A catch block is provided that catches a double, so things proceed properly
true
If B is a base class of D, then D's members cannot access the private data members of B without regard to the kind of inheritance.
true
In type matching to select a catch block, only exact matches work
true
Inheritance does
1. Provide facilities for class libraries; 2. Reuse code 3. Allow for Darwinian selection of class features as inheritance proceeds
Which of the following are events that a programmer would want to throw an exception to manage?
A user enters a name too long for the C-string buffer, threatening a buffer overflow.
Suppose we have a class D derived from base class B, Make the following call using dObj as calling object: dObj.func(); Which of the following is the version of func that is called?
D::func()
An exception is propagated
From the throw statement buried in the try block to the handler in the catch block
If B is a public base class of D, then D's members cannot invoke public members functions of B.
Incorrect
The ability to reuse objects already defined, perhaps for a different purpose, with modification appropriate to the new purpose, is referred to as:
Inheritance
When class D is derived from class B, the base class is usually smaller
true
Consider the class inheritance. class B{ public: B(); B(int nn); void f(); void g(); private: int n; }; class D: public B{ public: D(int nn, double dd); void h(); private: double d; }; How many public members (including constructors) does an object of class D have?
There are 4 public members. One constructor and one public member of its own and 2 public members inherited from the base class. Constructors are not inherited.Explanation: With public inheritance, public members of the base class become public members of the derived class.
An uncaught exception in C++ is ignored
false