GeekInterview.com
   Home |  Tech FAQ  |   Interview Questions |  Placement Papers |  Tech Articles |  Learn |  Freelance Projects |  Online Testing |  Geeks Talk |  Job Postings |  Knowledge Base | Site Search |  Add/Ask Question

GeekInterview.com  >  Interview Questions  >  Programming  >  C++
Go To First  |  Previous Question  |  Next Question 
 C++  |  Question 159 of 185    Print  
inheritance
what is inheritance? why we use it? plzz can anybody explain me with one example and where we use that concept?


  
Total Answers and Comments: 4 Last Update: April 03, 2008     Asked by: chaitugoud 
  
 Sponsored Links

 
 Best Rated Answer

No best answer available. Please pick the good answer available or submit your answer.
February 18, 2008 00:43:27   #1  
iammilind Member Since: February 2008   Contribution: 7    

RE: inheritance

It's a concept of deriving all the functionality of a class/structure into other class/structure (generally both are user defined). Inheritance will omit the the requirement of declaring a base object inside a derived object.

struct base{
// members of base
};

Now, if you are using C then we can have the derived structure functionality implemented as below:

struct derived{
base obj;
// members of derived
};

but in C++ it is like following:

struct derived : <inheritance type> base{
// members of derived
};
where inheritance type = public, protected, private



 
Is this answer useful? Yes | No
March 03, 2008 11:40:52   #2  
Samuel Sanchez Member Since: March 2008   Contribution: 1    

RE: inheritance
Inheritance is the capability of one class(derived class) to inherit properties i.e data members & functions of the base class.It supports reusability of code & is able to simulate the transitive nature of real life objects..It has many forms':Single inheritance,
multiple inheritance,
hierarchial
& multilevel inheritance

 
Is this answer useful? Yes | No
March 19, 2008 23:00:32   #3  
r.praveenkumar Member Since: October 2007   Contribution: 26    

RE: inheritance
using inheritance we can derive some codes from one class to another if it is not private.
inheritance is used to establish a relation between one class and another class(it can be done with two non related classes also but we should not do that it would be a bad programming).
with the help of inheritance we can avoid typing some codes repeatedly.

for example
class base
{
public void display()          //if display() is private we will get an error
{
cout<<"inherited";
}
};
class der : public base
{
};
void main()
{
der o=new der();
o.display();                //though display() is not in der we had inherited it from base so
}                                //it would print inherted

 
Is this answer useful? Yes | No
April 03, 2008 09:12:15   #4  
ganeshmoorthy Member Since: April 2008   Contribution: 2    

RE: inheritance

The main use of inheritance is to provide reusability of codes .Through inheritance base class objects and functions are acquired by derived class so there is no need to specify it again in derived class


 
Is this answer useful? Yes | No


 
Go To Top


 Sponsored Links

 




About Us  |   Privacy Policy  |   Terms and Conditions  |   Contact  |   Site Map  |   Add Question  |   Propose Category  |   RSS Feeds  |   Articles Sitemap  |   Site Updates  |   Add Resource

Copyright © 2005 - 2008 GeekInterview.com. All Rights Reserved
Page copy protected against web site content infringement by Copyscape