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

What is polymorphism and why is it important?

0 Answers  


What is the importance of oop?

0 Answers  


What is the outcome of the line of code "cout<<abs(- 16.5);"? 1) 16 2) 17 3) 16.5

16 Answers   TCS,


What is the differances between a abstract calss and interface

5 Answers   Aviva, Symphony,


What is encapsulation in oops?

0 Answers  






WILL I GET A guaranteed JOB AFTER DOING bsc()IT) and GNIIT from an NIIT CENTRE??

21 Answers   Biocon, MIT, NIIT,


What is the fundamental idea of oop?

0 Answers  


What is the main purpose of inheritance law?

0 Answers  


What is object in oop?

0 Answers  


Tell me the scenario,Where we can use interfaces or Abstract class.And What is the difference between interfaces and abstract class?

5 Answers  


What is polymorphism and example?

0 Answers  


what is the diffrence between c# and c++

5 Answers  


Categories