Quiz: Inheritance

To View Tricks: Login Required

Number of Questions: 20

Question: 11 -

Which among the following is correct for multiple inheritance?

Options:
  1. class student{int marks;}; class stream:public student{ };

  2. class student{int marks;}; class stream{ }; class topper: public student{ };

  3. class student{ }; class stream{ }; class topper{ };

  4. class student{public: int marks;}s; class stream{int total;}; class topper:public student, public stream{ };

  5. Answer:

    class student{public: int marks;}s; class stream{int total;}; class topper:public student, public stream{ };

    Solution not available.

Question: 12 -

Which among the following best defines single level inheritance?

Options:
  1. A class which gets inherited by 2 classes

  2. A class inheriting a nested class

  3. A class inheriting a base class

  4. A class inheriting a derived class

  5. Answer:

    A class inheriting a base class

    Solution not available.

Question: 13 -

Which is the correct syntax of inheritance?

Options:
  1. class derived_classname : base_classname{ /*define class body*/ };

  2. class base_classname :access derived_classname{ /*define class body*/ };

  3. class derived_classname : access base_classname{ /*define class body*/ };

  4. class base_classname : derived_classname{ /*define class body*/ };

  5. Answer:

    class derived_classname : access base_classname{ /*define class body*/ };

    Solution:

    Firstly, keyword class should come, followed by the derived class name. Colon is must followed by access in which base class has to be derived, followed by the base class name. And finally the body of class. Semicolon after the body is also must.


Question: 14 -

How many basic types of inheritance are provided as OOP feature?

Options:
  1. 2

  2. 4

  3. 3

  4. 1

  5. Answer:

    4

    Solution:

    There are basically 4 types of inheritance provided in OOP, namely, single level, multilevel, multiple and hierarchical inheritance. We can add one more type as Hybrid inheritance but that is actually the combination any types of inheritance from the 4 basic ones.


Question: 15 -

 Which among the following is correct for a hierarchical inheritance?

Options:
  1. One base class can be derived into only 2 classes

  2. One base class can be derived into other two derived classes or more

  3. Two base classes can be used to be derived into one single class

  4. Two or more classes can be derived into one class

  5. Answer:

    One base class can be derived into other two derived classes or more

    Solution:

    One base class can be derived into the other two derived classes or more. If only one class gets derived by only 2 other classes, it is also hierarchical inheritance, but it is not a mandatory condition, because any number of derived classes can be there.