Inheritance With Constructor

 #include<iostream>

using namespace std;
class A{

public:
int abc=123;
A(){
cout<<"Counstructor A "<<endl;
}

~A(){
cout<<"Destructor A "<<endl;
}

void display(){
cout<<"Display A";
}
};

class B:public A{
public:
int xyz=123;
B(){
display();
cout<<"Counstructor B "<<endl;
}

~B(){
cout<<"Destructor B you\'r "<<endl;
}

void display(){
cout<<"Display B";
}
};



int main(){
B obj;
cout<<"Sum="<<(obj.abc+obj.xyz);

return 0;
}

Comments

Popular posts from this blog

Dynamic Memory2

Template

MultiLevel