Recent Post
About me
My name is Frankentein I’m a programmer...
Basic introduction Inheritance is the element which is of object-oriented programing. It allows you to create a cl...
#include<iostream.h>
#include<conio.h>
class Parent //Base class
{
public:
int a;
};
class Child : public Parent // Sub class inheriting from Base Class(Parent)
{
public:
int b;
};
void main() //main function
{
Child obj; // An object of class child has all data members and member functions of class parent
obj.b = 10;
obj.a = 20;
cout << "Child b is " << obj.b << endl;
cout << "Parent a is " << obj.a << endl;
getch();
}
Output:
Child b is 10
Parent a is 20
|
|
Output: This is a class 1
This is a class 2
This is a class 3
|
|
My name is Frankentein I’m a programmer...