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
Is data hiding and abstraction same?
What is meant by oops concept?
How oops is better than procedural?
write a code for this. serial_number contained in the header of the file will be read , if this serial number is less than a previous serial number within a successfully processed file, or is the same as another serial number within a successfully processed file, or if the field contains anything other than 7 digits, then the file must error with the reason ‘Invalid SERIAL_NUMBER’.
There are two base class B1,B2 and there is one class D which is derived from both classes, Explain the flow of calling constructors and destructors when an object of derived class is instantiated.
What is constructor in oop?
What is abstraction in oops with example?
What is the problem with multiple inheritance?
Give an example where we have to specifically use C programming language and C++ programming language cannot be used?
What is the renewal class?
What is polymorphism in oops with example?
What is polymorphism and types?
What does it mean when someone says I oop?
What is cohesion in oop?
What is abstraction oop?