Questions on inheritance in C++ with Answers

Jan 11 • Notes • 11514 Views • 1 Comment on Questions on inheritance in C++ with Answers

In object oriented programming Inheritance is a way to establish a relationship between objects. Inheritance is one of important concepts in programming world. Here we have created  10 questions on Inheritance , which will be really helpful for clearing the basic concepts. These questions can be asked in any interview.

1. What is inheritance?

Inheritance

A typical example of inheritance in OOP

Ans. Inheritance in C++ is one of the best feature of OOPS. Inheritance is the method by which the features of a existing class can be used with new class. It enhances the concept of re-useability   of code as the code once written can be reused and other features can also be added. It is also possible that a class can’t be inherited, for this purpose we have to change the access specifier of the parent class.

 

2. How to implement inheritance ?

Ans. A class which is to be inherited should be declared public and then only it can be inherited. Example :

public class A

{

—–

}

class B : A

{

—-

}

 

3. What is Base class ?

Ans. Base class is a class from which other classes are derived or other classes inherits its features. It is also called as highest class i.e Base class cannot inherit from any other class.

 

4. What is Subclass?

Ans. Subclass is a class which inherits base class features.It is also called Child class.

 

5. What is the difference between public and private access specifier ?

Ans. When a class is declared public then its features can be inherited by other class means it is available for other classes but when it is declared private then it can not be inherited and it can not be reused.

 

6. What are the advantages of inheritance ?

Ans.  Code re-useability  & Time saving in code writing.

 

7. What are the types of inheritance ?

Ans :

  1. Single inheritance
  2. Multiple inheritance
  3. Multilevel inheritance
  4. Hierarchical inheritance
  5. Hybrid inheritance

 

8. How to implement data and functionality as a single entity ?

Ans : By declaring data and functionality in a class they can be represented as single entity.

 

9. What is the difference between inheritance and polymorphism ?

Ans.  Inheritance – It is the concept of code reusability  by which the code written once can be used again without writing it again. We can also add new features in it by writing in new class.

Polymorphism – It is also an OOPS concept , in this a single function can be given more than one form. Poly means many and morphism means Forms.

 

10.  Is inheritance possible in C ?

Ans :  Inheritance is a OOPS ( Object Oriented Programming ) concept which is not used in C. We use “concept of class in inheritance” so inheritance is not supported in C.

If you have any Query / Suggestion Please leave a comment .

Related Posts :

  1. Interview questions on C
  2. C/C++ Aptitude questions
  3. Questions on C++
  4. C Aptitude questions

 

Tell us Your Queries, Suggestions and Feedback

Your email address will not be published.

One Response to Questions on inheritance in C++ with Answers

  1. ramzan akbar says:

    this is very good method to understand the concept of inheritance .i likeeeeeee it very much

« »