Note: (Restricted functionality due to obvious reasons!)

For Mobile-Ease ⇓

Minimal Code ( Raw-View ) :
#include<iostream.h> #include<conio.h> class C1{ private: int prv1; protected : int prt1; public: int pb, pb2, pb3; C1(){ prv1 = 63; pb = 937; prt1 = 1009; cout<<endl<<" +++++ Constructor C1 -Parent class running +++"<<endl; } ~C1(){ cout<<endl<<"\n -----Destructor of Parent class running +++"<<endl; } }; class C2 : public C1{ // C2 -child of C1 protected : int i2; // i2 not directly accessible (in main) but in child classes public : C2(){ i2 = 234; cout<<"\n ++++ Child C2 Constructor +++++ \n"; } ~C2(){cout<<"\n ---- Child C2 Destructor ----- \n";} }; class C3 : public C2 { public: int i2 ; C3(){ this->i2 = C2::i2 * 3 ; // this-> pointer for clarification cout<<" \n +++ C3 child created." ; cout<<" Protected Member of C1 :"<<prt1<<" +++ \n "; } ~C3(){cout<<"\n --- Child C3 Destructor --- \n";} }; void fnc1(){ C3 obj90; cout<<endl<<" Value of int-i2 in object-variable of C3 : "<<obj90.i2; } void main(){ fnc1(); // shows the scope of constructors + destructors (+ their running sequence) /* Pragram concepts: + Inheritance ++ Constructors & Destructors (and their scope) (showing constructor+Destructor of parent classes running in child class) + Access Modifiers : + private :(strictly by that class members eg. int prv1; ) + protected : (NOT-directly but accessible to members of that + child classes) + public :(by that class, child classes, anywhere outside diretly) + Pointers usage with object-variables */ cout<<"\n ********************************************** "; cout<<"\n *** Using *Pointers to access object->members \n\n"; C3 obC3a, *ptrC3 ; ptrC3 = &obC3a; cout<<"\n Value in object-reference : "<< obC3a.pb; cout<<"\n Value in pointer : "<< ptrC3->pb; C2 *pN; pN = new C2(); cout<<endl<<pN->pb; // An object of C1 with Default-Constructor is created // but without a reference-Name. and "new" points to it in memory. // the address (returned by new) is stored in pointer "pN" delete pN; // delete always deletes a pointer. }