Chapter 10 Inheritance
Chapter 10 Inheritance
ANS: C++ allows the user to create a new class (derived class) from an existing class (base class).
3. What is a base class?
ANS: Base Class is the class whose properties are inherited by another class. It is also called Super class.
4. What is derived class?
ANS: Derived Class is the class that inherits the properties from base class. It is also called Sub class.
5. Give any one advantage of inheritance?
ANS: Reusing existing code
6. What is singe level inheritance?
ANS: Single Inheritance is the process of creating a new class from existing class base class.
7. What is multilevel inheritance?
ANS: Derivation of a class from another derived class is called multilevel inheritance.
8. What is hierarchical inheritance?
ANS: If a number of classes are derived from a single base class, it is called as hierarchical inheritance.
9. What is hybrid inheritance?
ANS: Hybrid Inheritance is combination of Hierarchical and multilevel inheritance.
………..
};
………..
};
ANS: If a number of classes are derived from a single base class, it is called as hierarchical inheritance.
6. What is hybrid inheritance? Give an example.
ANS: Hybrid Inheritance is combination of Hierarchical and multilevel inheritance.
};
class Derived_class : public Base_calss
………..
};
i) When a base class is inherited as public, all public members of the base class become public members of
derived class.
ii) The private members of the base class are nor accessible by members of the derived class.
5. Explain private inheritance.
ANS: Private Inheritance:
i) When a base class is inherited as private, then all public and protected members of the base class become
ii) The private members of the base class are nor accessible by members of the derived class..
6. Explain protected inheritance.
ANS: Protected Inheritance:
i) When a base class is inherited as protected, then all public and protected members of the base class become
ii) The private data members of base class are not visible to derived class.
ANS: Inheritance: Inheritance is the capability of one class to inherit properties from another class.
Types of Inheritance:
i) Single Inheritance
ii) Multilevel Inheritance
iii) Multiple Inheritance
iv) Hierarchical Inheritance
v) Hybrid Inheritance
i) Single Inheritance: Single Inheritance is the process of creating a new class from existing class base class.
ii) Multilevel Inheritance: Derivation of a class from another derived class is called multilevel inheritance.
Hierarchical Inheritance:
If a number of classes are derived from a single base class, it is called as
hierarchical inheritance.
Hierarchical model exhibits top down approach by breaking up a complex
class into simpler class
Hybrid Inheritance:
Hybrid Inheritance is combination of Hierarchical and multilevel inheritance.
2. What are the advantages of inheritance? (U)
ANS: i) Reusing existing code
ii) Faster development time
iii) Easy to maintain
iv) Easy to extend
v) Memory Utilization
3. What is visibility mode? Explain private and public inheritance.
ANS: Visibility mode:
Visibility mode can be public, private or protected. The private data of base class cannot be inherited.
1) Public: If inheritance is done in public mode, public members of the base class become the public member of
derived class and protected member of base class become the protected member of derived class..
2) Private: If inheritance is done in a private mode, public and protected members of base class become the
private members of derived class.
3) Protected: If inheritance is done in a protected mode, public and protected members of base class become the
protected members of the derived class.