inheritence with example

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


Please Help Members By Posting Answers For Below Questions

given a set based questions and 5 questions based on it next data sufficiciency questions 2 and 2/3 english sentence completion with options very easy and 2 synononmys paragraph with 10 questions 10 minutes replace =,-,*,% with -,%,+,* type questions 5 3 questions lik following itssickhere itssickthere itssickhere istsickhere which is nt alike the others very easy

2252


How do you define social class?

681


What is destructor oops?

712


What is difference between abstraction and encapsulation?

691


What is the importance of oop?

698






How is polymorphism achieved?

664


what are the ways in which a constructors can be called?

1676


What is data binding in oops?

698


Are polymorphisms mutations?

798


What is the fundamental idea of oop?

737


Why is it so that we can have virtual constructors but we cannot have virtual destructors?

4042


What is abstraction example?

699


They started with the brief introduction followed by few basic C++ questions on polumorphism, inheritance and then virtual functions. What is polymorphims? How you will access polymorphic functions in C? How virtual function mechanism works?

1493


What are the three parts of a simple empty class?

1608


is there any choice in opting subjects like 4 out of 7

1822