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

swapping program does not use third variable

5 Answers   TCS,


Write a C/C++ program that connects to a MySQL server and checks if the InnoDB plug-in is installed on it. If so, your program should print the maximum number of concurrent threads that the InnoDB plug-in can create.

1 Answers  


Why do we use inheritance?

0 Answers  


What is encapsulation in oop?

0 Answers  


What is Agile methodology?

20 Answers   ABC, Accenture, College School Exams Tests, Inmar, Microsoft, Sapient,






WHY FUCTION OVERLOADING DOSENOT RETURN A RETEN TYPE

2 Answers  


what is virtual function in c++

6 Answers  


What is advantage of inheritance?

0 Answers  


What is a unary operator?

5 Answers  


what is the function of 'this' operator ?

7 Answers   Wipro,


What are callback functions in c++

1 Answers   SoftTech,


Why is encapsulation used?

0 Answers  


Categories