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 |
String = "C++ is an object oriented programming language.An imp feature of oops is classes and objects".Write a pgm to count the repeated words from this scenario?
Can we override main method?
how to find no of instances of an object in .NET?
What is difference between function overloading and overriding?
What is encapsulation in simple terms?
What is debug class?what is trace class? What differences are between them? With examples.
How do you explain polymorphism?
Can we call a base class method without creating instance?
How to use CMutex, CSemaphore in VC++ MFC
What is this interview room ? Is it a class or an object.
can you give the dynamic polymorphism types?
The company is a fake company asking for money of RS10000 while training and not offering a job after training. My humble request to you people not to attend Astersys interview