inheritence with example



inheritence with example..

Answer / poonam

Inheritance is deriving a new class or classes from its base
class or classes.
Inheritance is of basically five types:
-Single inheritance
-Multiple inheritance
-Multilevel inheritance
-Hierarchical inheritance
-Hybrid inheritance

There are three modes by which we can inherit a class.
1.Private visibility mode
2.Public visibility mode
3.Protected visibility mode

Eg:-

#include<iostream>
using namespace std;
class base
{
private:
int a;
public:
void geta()
{
cout<<"\nEnter the value of 'a':;
cin>>a;
}
void puta()
{
cout<<"\nValue of 'a' is:"<<a;
}
};
class derived:public base //base class is ...
{ //publically inherited
private:
int b;
public:
void getb()
{
cout<<"\nEnter the value of b:";
cin>>b;
}
void putb()
{
cout<<"\nValue of b is:"<<b;
}
};
int main()
{
derived d;
d.geta();
d.puta();
d.getb();
d.putb();
return 0;
}

Is This Answer Correct ?    11 Yes 0 No

Post New Answer

More OOPS Interview Questions

Can we call a base class method without creating instance?

6 Answers  


the difference between new and malloc

5 Answers   Siemens,


1.what are two type of classe members called? 2.what is data hiding and data encapsulation? 3.how do you make a class member visible aouside its class? 4.what is the default visibility of a class data member? 5.what are the advantages of oop over the structured programing?

6 Answers  


What do you mean by inline function?

6 Answers  


create a c++ program that will ask 10 numbers and display their sum using array.

1 Answers  






i^=j; j^=i; i^=j; value of i,j

1 Answers  


What does <> mean pseudocode?

0 Answers  


What is the concept of object oriented program?

6 Answers  


What is a class and object?

0 Answers  


In multilevel inheritance constructors will be executed from the .... class to ... class

2 Answers   ABCO, TCS,


What is Hashing and how is it done? Pictorial form?

2 Answers   emc2, Wipro,


what is the difference between containership and inheritence?

1 Answers  


Categories