Inheritance

  1. The concept of inheritance enables C++
    1. to pass arguments to objects of classes
    1. to create new classes from existing classes
    1. to improve data hiding
    1. to support abstraction
  2. What is the advantage of using inheritance in C++?
    • Facilitates creation of class libraries
    • Enables reuse of existing code
    • Enhances reliability of the code
    • All the above
  3. Through inheritance, it is possible to inherit from a class
    • only data members
    • only members functions
    • any members as we desire
    • only functions declared as friend
  4. In the class definition
    1. class M : visibility-mode N
    2. {
    3. members of M
    4. };
    5. the visibility-mode
      • must be blank
      • must be public
      • must be private
      • may be blank, public or private
  5. Consider the code segment, The derived class C would contain the members ?
    1. class A
    2. {
    3. private : int a ; public : int b ; protected : int c ;
    4. };
    5. class B : A { };
    6. class C : public B { };
      • a, b and c
      • b and c only
      • b only
      • none
  6. Which of the following statements is TRUE, when a derived class D inherits a base class B using protected specifier?
    • public members of B become protected members of D
    • public members of B become public members of D
    • public members of B become private members of D
    • public members are not inherited
  7. Which of the following functions can have access to the protected data of a class?
    • A function that is friend of the class
    • A member function of a class declared friend of the class
    • A member function of a derived class
    • All the above
  8. The use of scope resolution operator in inheritance enables us
    • to restrict the visibility of data members
    • to determine the base class of a derived class
    • to specify a particular class
    • to make a private member inheritable
  9. The process of a class inheriting attributes from several classes is known as
    • multilevel inheritance
    • multiple inheritance
    • multipath inheritance
    • hybrid inheritance
  10. A class D is privately derived from class B. An object of D in the main function can access
    1. public members of B
    1. private members of D
    1. protected members of B
    1. public members of D
  11. The following examples show that the class C is derived from classes A and B. Which one of them is legal?
    • class C : private A, public B
    • class C :: private A, public B
    • class C : public A : public B
    • class C: class A, B
    • class C: private A, public B;
  12. Consider the following code: What happens when we compile this code?
    1. class A { };
    2. class B : A { };
      • Will not compile because the body of A is empty
      • Will not compile because the body of B is empty
      • Will not compile because the visibility mode for A is not specified
      • Will compile successfully
  13. Which one of the following statements is FALSE?
    • If no constructors are declared for the derived class, the objects of the derived
    • class will use the constructors in the base class
    • There may be situations where we may have to define a class which will never be used to create objects
    • It is legal to make objects of one class as members of another class.
  14. Consider the following class definition with inheritance: The order of execution of constructors will be:
    1. class A : public B, virtual public C
    2. {
    3. };
      • A ( ), B ( ), C ( )
      • C ( ), B ( ), A ( )
      • B ( ), C ( ), A ( )
      • A ( ), C ( ), B ( )
  15. Consider the following class.We wish to define the constructor function using an initialization list. Which one of the following is the legal constructor function?
    1. class ABC
    2. {
    3. int a; int b;
    4. public : constructor function
    5. };
      • ABC (int x, int y): a (x), b(y) { }
      • ABC (int x, int y): b (x), a(x+y) { }
      • ABC (int x, int y): a (x), b(a*y) { }
      • All of the Above

Answers:

  1. to create new classes from existing classes
  2. All the above
  3. any members as we desire
  4. may be blank, public or private
  5. none
  6. public members of B become protected members of D
  7. All the above
  8. to specify a particular class
  9. multiple inheritance
  10. public members of D
  11. class C : private A, public B
  12. Will compile successfully
  13. Deriving one class from another requires fundamental changes to the base class.
  14. A ( ), B ( ), C ( )
  15. All the above

Related posts