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 |
How do you define a class in oop?
what is the diffrence between c# and c++
What is abstract class in oops?
What is Hashing and how is it done? Pictorial form?
what is the function of 'this' operator ?
Explain the concept of abstracion and encapsulation with one example. What is the difference between them?
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’.
How can i write a code in c# to take a number from the user and then find all the prime numbers till the number entered by the user.
what are the realtime excercises in C++?
Why is static class not inherited?
What do you mean by inline function?
what are the uses of C++