Today I have just learned about Inheritance in C++ programming. I thought I should share what I learnt today !! I hope it will be helpful for anyone...
Inheritance in Object Oriented Programming can be described as a process of creating new classes from existing classes. New class or classes inherit some part from an existing class or classes. There we have total 6 kind of inheritance in C++ and those are...
- Single inheritance.
- Multi-level inheritance...
- Multiple inheritance.
- Multipath inheritance.
- Hierarchical inheritance
- Hybrid inheritance.
Example program of Single inheritance...
#include <iostream>
#include <conio.h>
#include <string>
using namespace std;
class student
{
public:
int roll;
char name[30];
void getroll()
{
cout << "Please enter your roll : "<< endl;
cin >> roll;
}
void showroll()
{
cout << "Your Roll is : " << roll << endl;
}
};
class student_2 : public student
{
public:
void getname()
{
cout << "Please enter your name" << endl;
cin >> name;
}
void showname()
{
cout << "Your name is : "<< name << endl;
}
};
int main ()
{
student_2 a;
a.getroll();
a.getname();
a.showroll();
a.showname();
getch();
return 0;
}
simicartan
Also I want to add up a bit: Inheritance in Object Oriented Programming can be described as a process of creating new classes from existing classes. ... An existing class that is "parent" of a new class is called a base class. New class that inherits properties of the base class is called a derived class. Inheritance is a technique of code reuse.
App Marketing Made Easy Thanks for your clear explanation of inheritance. Also I want to add up a bit: [b]Inheritance[/b] in Object Oriented Programming can be described as a process of creating new classes from existing classes. ... An existing class that is "parent" of a new class is called a base class. New class that inherits properties of the base class is called a derived class. [b]Inheritance[/b] is a technique of code reuse. [size=50][url=https://www.simicart.com/blog/easy-and-free-app-marketing-tips/]App Marketing[/url] Made Easy[/size]
Are you sure you want to delete this post?