Tuesday, 24 February 2015

Base Class Initialization Program Using C++

// Base Class Initialization

#include<iostream.h>
#include<conio.h>

class Base
{
protected:
int a,b;
public:
Base()
{
a=0;
b=0;
}
Base(int A,int B)
{
a=A;
b=B;
}
};
class Derived:public Base
{
private:
int c;
public:
Derived()// automatically call Base Class Constructor
{
c=0;
}
Derived(int A,int B,int C):Base(A,B)
{
c=C;
}
void Put()
{
cout<<"\n A =  "<<a;
cout<<"\n B =  "<<b;
cout<<"\n C =  "<<c;
}
};
void main()
{
Derived d,d1(10,20,30);
clrscr();
d.Put();

d1.Put();
getch();
}

No comments:

Post a Comment