Answer Posted / 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 View All Answers
write a C++ program for booking using constructor and destructor.
Why do we use inheritance?
Why is encapsulation used?
Plese get me a perfect C++ program for railway/airway reservation with all details.
Can you inherit a private class?
Write a program to implement OOPS concepts such as inheritance, polymorphism, friend function, operator overloading?
Why multiple inheritance is not possible?
How is polymorphism achieved?
Explain virtual inheritance?
What is meant by multiple inheritance?
How to improve object oriented design skills?
What is the benefit of oop?
• What are the desirable attributes for memory managment?
Can destructor be overloaded?
What is abstraction oop?