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 |
swapping program does not use third variable
Write a C/C++ program that connects to a MySQL server and checks if the InnoDB plug-in is installed on it. If so, your program should print the maximum number of concurrent threads that the InnoDB plug-in can create.
Why do we use inheritance?
What is encapsulation in oop?
What is Agile methodology?
20 Answers ABC, Accenture, College School Exams Tests, Inmar, Microsoft, Sapient,
WHY FUCTION OVERLOADING DOSENOT RETURN A RETEN TYPE
what is virtual function in c++
What is advantage of inheritance?
What is a unary operator?
what is the function of 'this' operator ?
What are callback functions in c++
Why is encapsulation used?